Python Part 2
Python Part 2
followed
Jan 31
Feb 29
Mar 31
Apr 30
I. Write the code to add one row ‘May’=31
II. Write the code to update Feb to 29
III. Write the code to change index to 1,2,3,4,5 in place of Jan, Feb, Mar,
Apr and May
IV. Write a code to print a month name having number od days less than
31
V. Write the output:
(a) print(SerObj<30)
(b)print(SerObj+3)
Ans)
import pandas as pd
S={"Jan":31,"Feb":28,"Mar":31,"Apr":30}
SerObj=pd.Series(S)
print(SerObj)
print("\n")
SerObj['May']=31
print(SerObj)
print("\n")
SerObj['Feb']=29
print(SerObj)
print("\n")
SerObj.index=[1,2,3,4,5]
print(SerObj)
print("\n")
SerObj[SerObj<31]
print(SerObj)
print("\n")
print(SerObj<30)
print("\n")
print(SerObj+3)
28
Output)
29
Q22) Write a program to display a bar chart of number of students
I. Use different colour for each bar
II. Title for X axis should be “Groups” and Title for the Y axis should be
“Number of Students”
Ans)
import matplotlib.pyplot as plt
Groups=['I','II','III','IV']
Strenght=[38,30,45,49]
plt.bar(Groups,Strenght,color=['r','g','b','c'])
plt.xlabel("Groups")
plt.ylabel("Number of Students")
plt.show()
Output)
30