PROBLEM SOLVING USING PYTHON
Q1) Write the code to create the series ‘serObj’ and answer the questions followed.
Jan 31
Feb 28
Mar 31
Apr 30
i) Write the command to add one row: ‘May’ – 31
ii) Write the command to update Feb to 29
iii) Write the command to change index to 1,2,3,4,5 in place of Jan, Feb, Mar, Apr and May.
iv) Write a command to print a month name having number of days less than 31.
v) Write the output:
(a) print(serObj<30)
(b) print(serObj + 3)
Source code :
i) import pandas as pd
serObj = pd.Series(data=[31,28,31,30],index=['Jan','Feb','Mar','Apr'])
print(serObj)
serObj['May']=31
ii) serObj['Feb']=29
iii) newind=[1,2,3,4,5]
serObj.index=newind
print(serObj)
iv) print(serObj[serObj<31])
v) a) print(serObj<30)
b) print(serObj+30)
1|Page