Python Programming Lab Programs
Python Programming Lab Programs
(Autonomous Institution, Affiliated to VTU, Belgaum, Approved by AICTE & State Govt. of Karnataka)
DEPARTMENT OF M.C.A.
Python Programming
Laboratory
22MCA207L
LAB MANUAL 2022-24
Note:
1. In the examination each student should pick one program from Part-A,
2. A team of two or three students must develop the mini project. However during the
examination, each student must demonstrate the project individually.
3. The team must submit a brief project report (15-20 pages)
Output:
Output:
Output:
stack = deque()
print('Initial stack:')
print(stack)
print('Initial stack')
print(stack)
# Calling constructor of
# Base class
Base.__init__(self)
print("Calling private member of base class: ")
print(self.__c)
# Driver code
obj1 = Base()
print(obj1.a)
Output:
Ob1 = complex(1, 2)
Ob2 = complex(2, 3)
Ob3 = Ob1 + Ob2
print(Ob3)
Output:
Output:
The interpreter will read the first five characters of stored data and return it as a string
3. Append function:
# Python code to illustrate append() mode
file = open('geek.txt','a')
file.write("This will add this line")
file.close()
4. Split function:
# Python code to illustrate split() function
with open("file.text", "r") as file:
data = file.readlines()
for line in data:
word = line.split()
print (word)
# Creating Dataframe
details = pd.DataFrame({
'ID': [101, 102, 103, 104, 105,
106, 107, 108, 109, 110],
'NAME': ['Jagroop', 'Praveen', 'Harjot',
'Pooja', 'Rahul', 'Nikita',
'Saurabh', 'Ayush', 'Dolly', "Mohit"],
'BRANCH': ['MCA', 'EEE', 'ISE', 'MECH', 'CSE',
'ECE', 'MBA', 'AERO', 'MCA', 'CIVIL']})
# Creating Dataframe
fees_status = pd.DataFrame(
{'ID': [101, 102, 103, 104, 105,
106, 107, 108, 109, 110],
'PENDING': ['5000', '250', 'NIL',
'9000', '15000', 'NIL',
'4500', '1800', '250', 'NIL']})
# Merging Dataframe
print(pd.merge(details, fees_status, on='ID'))
# Concatination
print (pd.concat([details, fees_status]))
#diaplay non duplicate value
df = pd.DataFrame(fees_status)
1. Importing Dataset:
import pandas as pd
df = pd.read_csv('csv.csv')
print(df.to_string())
CSV file:
Output:
print(pd.options.display.max_rows)
Output:
import pandas as pd
data = {'name': ['Alice', 'Bob', 'Charles', 'David', 'Eric'],
'year': [2017, 2017, 2017, 2017, 2017],
'salary': [40000, 24000, 31000, 20000, 30000]}
data1 = pd.DataFrame({
Lab Manual for Python Programming Laboratory-22MCA207L
'Name': ['Billy', 'Brian', 'Bran', 'Bryce', 'Betty'],
'subject_id':['sub2','sub4','sub3','sub6','sub5'],
'Marks_scored':[89,80,79,97,88]},
print(df)
Output:
Filtering option:
1. df_filtered = df.query('salary>30000')
print(df_filtered)
Output:
Output:
newarr = arr.reshape(2, 3, 2)
print(newarr)
#splitting of array
import numpy as np
arr = np.array([[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]])
newarr = np.array_split(arr, 3)
print(newarr)
Output: