DATAFRAME
DATAFRAME
[[201,’Gurmeet’,95],[202,’Praveen’,89],[203,’Suman’,97],[204.’Yogesh’,91]]
3) Write a Python code to create a DataFrame ‘stud’ using series with specified column
headings, index and data:
5) Write a Python code to create a DataFrame ‘Toppers’ using dictionary of series with
specified column headings, index and data:
6) Write a Python code to create a DataFrame ‘stud’ using list of dictionaries with
specified column headings, index and data:
8) Write a Python code to create a DataFrame ‘Df’ using dictionary of dictionaries for
the following data.
9) Write a Python code to create a DataFrame with appropriate column headings from
the list given
below:
[[1001,'IND-AUS',’2022-10-17’], [1002,'IND-PAK',’2022-10-23’], [1003,'IND-SA' ,
‘2022-10-30],
[1004,'IND-NZ',’2022-11-18’]]
10) Write a Python code to create the below dataframe ‘Items’ by passing 3 series
DATAFRAME OPERATIONS
Name Price
CHESS 150
CARROM BOARD 900
LUDO 100
FOOTBALL 700
Write suitable Python statements for the following:
i. Add a column called DISCOUNT with the following data: [15,90,10,70].
ii. Add a row with the values BADMINTON 200 20
iii. Remove the column DISCOUNT.
import pandas as pd
data = [{'a': 10, 'b': 20},{'a': 6, 'b': 32, 'c': 22}]
df1 = pd.DataFrame(data)
print(df1)
2) Consider the code given below and answer the following question:
Ld=[{'a':10,'b':20},{'a':5,'b':10,'c':20}]
df=pd.DataFrame(Ld)
print(df)
import pandas as pd
player1={'IG1':34,'IG2':0,'IG3':23}
player2={'IG1':21,'IG2':10,'IG3':39}
pl={'p1':player1,'p2':player2}
df=pd.DataFrame(pl)
import pandas as pd
L=[['S101','Anushree',65],['S102','Anubha',56],['S104','Vishnu',67],['S105','Kritika',45]]
df=pd.DataFrame (L, columns=['ID','Name','Marks'])
print(df)
import pandas as pd
D1={'S1': 'India', 'S2': 'Russia', 'S3': 'World'}
D2={'School': 'EOIS', 'Place': 'Moscow'}
data={1:D1,2:D2}
df=pd.DataFrame(data)
print(df)
i) print(df[1:3])
ii) print(df.loc[1,'Quantity'])
b) Write the python statement to get the price of the watch using loc function.
3) Given a dataframe df
i) print(df.loc[1,'Quantity'])
ii) print(df[1:3])
iii) print(df.iloc[1:3,2])
iv) print(df.loc[1:2,'Price'])
v) print(df.iloc[1:2,2:4])
i) print(df.size)
ii) print(df.count())
iii) print(df.isnull())
iv) print(df['Price'].isnull())
v) print(df['Quantity'].count())
vi) print(df.T)
vii) print(df.ndim)
viii) print(df['Quantity'].values)
ix) print(df.empty)
x) print(df.shape)