Exp 4 To 10
Exp 4 To 10
import pickle
file=open("newbfile.dat","ab")
d={}
a=int(input("enter range"))
for i in range(a):
d["Rollno"]=int(input("enter rollno"))
d["name"]=input("enter name")
d["marks"]=int(input("enter marks"))
pickle.dump(d,file)
print("written successfully")
file.close()
Output:
Experiment 5: Write a program to read the information of students from a file and print them on
Screen.
import pickle
file=open("newbfile.dat","rb")
try:
while True:
l=pickle.load(file)
print(l)
except EOFError:
pass
file.close()
Output:
Experiment 6. Write the Programs to show the operation using Pandas.
a)
b)
Experiment 7.: Write a program to demonstrate working with dictionaries in python.
print(college)
college["location"] = "Kharar"
print(college)
college["location"] = "Gharuan"
print(college)
college.pop("code")
print(college)
mycollege= college.copy()
print(mycollege)
Output:
7. (b) Create a program to show the performance of Batsmen using Dictionary.
import pandas as pd
squad = {'Batsmen': {'Rohit Sharma': {'Matches': 206,
'Runs': 8010,
'Average':47.4,
'Highest Score': 264 },
'Shikhar Dhawan': {'Matches':128,
'Runs': 5355,
'Average': 44.62,
'Highest Score': 143},
'Virat Kohli': {'Matches': 227,
'Runs': 10843,
'Average': 59.58,
'Highest Score': 183}}
df = pd.DataFrame(squad['Batsmen'])
print(df)
Output:
Experiment 8: Program to compute the mean, standard deviation, and variance of a given array
along the second axis.
import numpy as np
# Original array
x = np.arange(5)
print(x)
r11 = np.mean(x)
r12 = np.average(x)
r21 = np.std(x)
r31 = np.var(x)
import numpy as np
# Original array1
print(array1)
# Original array2
print(array2)
# Covariance matrix
import numpy as np
print("nums: ",nums)
print("bins: ",bins)
plt.hist(nums, bins=bins)
plt.show()