The document provides instructions to create a DataFrame called Student with specified columns and values, and then perform various operations on it like filtering, inserting, deleting, modifying values. It describes 10 steps - creating the DataFrame, printing subsets of data, inserting new columns, deleting columns permanently and temporarily, modifying names and values.
The document provides instructions to create a DataFrame called Student with specified columns and values, and then perform various operations on it like filtering, inserting, deleting, modifying values. It describes 10 steps - creating the DataFrame, printing subsets of data, inserting new columns, deleting columns permanently and temporarily, modifying names and values.
The document provides instructions to create a DataFrame called Student with specified columns and values, and then perform various operations on it like filtering, inserting, deleting, modifying values. It describes 10 steps - creating the DataFrame, printing subsets of data, inserting new columns, deleting columns permanently and temporarily, modifying names and values.
Create the following DataFrame Student with index=1, 2,3,4,5 and 6 as roll number.
I Display Name and UT1 marks where UT1 is more than 20
print(Student[Student['UT1']>20][['Name','UT1']]) II Display Name and UT2 marks where UT2 is more than or equal to 20 print(Student[Student['UT2']>=22][['Name','UT2']]) III Display Name , UT1 and UT2 where UT1 >15 and UT2 >20. Student[Student['UT1']>15][Student['UT2']>20][['Name','UT1','UT2']] III Insert new column in DataFrame Student by the name FINAL with values 23, 22,24,21,19 & 18 as final marks. Any one of the following will Modify the value Student['FINAL']=[23,22,24,21,19,18] Student.loc[:,'FINAL']=[23,22,24,21,19,18] Student.insert(5,'FINAL',[23,22,24,21,19,18]) IV Insert new column in DataFrame Student by the name HLFYR with values 24, 22, 23, 21, 23 & 20 as half- yearly marks between UT2 and UT3. Student.insert(3,'HLFYR',[24, 22, 23, 21,23,20]) V Delete the newly added column HLFYR permanently from the DataFrame Student. Any one of the following will Modify the value del Student['HLFYR'] Student.drop(columns=’HLFYR’,inplace=True) Student.drop('HLFYR',axis=1,inplace=True) VI Delete the newly added column HLFYR temporally from the DataFrame Student. Student.drop(columns=’HLFYR’) Or Student.drop('HLFYR',axis=1) VII Suppose DataFrame Student have both columns ‘HLFYR’ and ‘FINAL’ columns. Is it possible to permanently delete both columns permanently? If yes. Do it. Student.drop(columns=['HLFYR','FINAL'],inplace=True) VII Suppose DataFrame Student have both columns ‘HLFYR’ and ‘FINAL’. Add new column GRADE in the last I with following value ‘A’. Student[‘Grade’]=’A’ or Student.insert(7,'Grade',['A','A','A','A','A','A']) IX Modify the name ‘Tanish Goel’ as ‘Tanishq Goyal’ in the DataFrame – Student Any one of the following will Modify the value Student['Name'][3]='Tanishq Goyal' Student.loc[3:3,'Name':'Name']= 'Tanishq Goyal' Student.loc[3,'Name']= 'Tanishq Goyal' Student.iloc[2,0]= 'Tanishq Goyal' Student.iloc[2:3,0:1]= 'Tanishq Goyal' Student.at[3,'Name']= 'Tanishq Goyal' Student.iat[2,0] ]= 'Tanishq Goyal' X Modify the marks of UT2 of Kanika Bhatnagar of the DataFrame Student to 19. Any one of the following will Modify the value Student['UT2'][5]=19 Student.loc[5,'UT2']=19 Student.loc[5:5,'UT2':'UT2']=19 Student.iloc[4,2]=19 Student.iloc[4:5,2:3]=19 Student.at[5,'UT2']=19 Student.iat[4,2]=19