Pandas-Series &DF-Term1-24-25
Pandas-Series &DF-Term1-24-25
3) Write a python code to create the following series object by using dictionary method.
4) Write a python code to create series data structure by using dictionary method.
Coding: import pandas as pd
d={1:'One',2:'Two',3:'Three'}
s=pd.Series(d)
print(s)
Output:
5) Write a python code to create series data structure by using scalar value method.
Coding: import pandas as pd
b=pd.Series('Yet to start',index=[5,10,15])
print(b)
Output:
6) Write a python code to create series data structure by using mathematical functions.
Coding: import numpy as np
import pandas as pd
b=np.arange(5)
d=pd.Series(b*2,index=['a','b','c','d','e'])
print(d)
Output: a 0
b 2
c 4
d 6
e 8
dtype: int32
Ex. No.2 OPERATIONS ON SERIES DATA STRUCTURE
1) Write a python program to create a series data structure which stores the monthly salary of 10
employees. Write a command to perform the following operations on it.
i. Display the first 3 employee’s salaries.
ii. Display the last 5 employee’s salaries.
iii. Display the annual income of employees.
iv. Display the names of employees who are getting salary more than 7000.
v. Display the salary of employees increased by 200.
2) Write a python code to print the following data frame by using dictionary of series.
Coding: import pandas as pd
names=pd.Series(['Malar','Arun','Mahi'])
classes=pd.Series(['XII','XI','XII'])
mark1=pd.Series([78,80,90])
mark2=pd.Series([96,98,90])
mark3=pd.Series([90,89,90])
dict={'Name':names,'Class':classes,'English':mark1,'Economics':mark2,'Accountancy':mark3}
stu_df=pd.DataFrame(dict)
print(stu_df)
Output:
2) Write a python code to convert dataframe into a CSV file with a name t.csv.
import pandas as pd
a.to_csv(r"t.csv",index=False,header=True)