DF Opeartions - 1 - Ak

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

REVISION – 1

1) Consider the given a dataframe ‘Emp’:

Write suitable Python statements for the following:

i. Add a column called ‘HRA’ with the following data:


[3500, 2500,5000,3200]

Emp['HRA'] = [3500, 2500,5000,3200]

ii. Add a new employee ‘Pawan’ in department ‘IT’ with basic pay 52000 and HRA
as 1000.

Emp.loc[4] = ['Pawan','IT',52000,1000]

iii. Rename the column ‘Name’ to ‘EmpName’.

Emp.rename({'Name':'EmpName'}, axis = 1, inplace= True)

iv. Deepak has resigned from the job, hence delete his record from the dataframe.

Emp.drop(3,axis = 0, inplace = True)

v. Set the index of the dataframe as ‘E01’, ‘E02’,’E03’ and ’E04’.

Emp.index = ['E01', 'E02','E03','E04']


2) Consider the given a dataframe ‘Store’:

i. Delete the column ‘Qtr4’ from the dataframe.

Store.drop('Qtr4', axis = 1, inplace = True)

ii. Add a new column ‘Total’ by adding the columns ‘Qtr1’ , ‘Qtr2’ and ‘Qtr3’.

Store['Total'] = Store['Qtr1'] + Store['Qtr2'] + Store['Qtr3']

iii. Set the column ‘Store’ as the index of the dataframe.

Store.set_index('Store', inplace = True)

iv. Add a new store ‘Store4’ with sales amount as 260, 200 195,655 for quarter1,
quarter2 , quarter3 and total sales respectively.
(Note the index is been replaced)

Store.loc['Store4'] = [260,200,195,655]

v. Delete the ‘Store3’ details.


(Note the index is been replaced)

Store.drop('Store3', inplace = True)

You might also like