KnowledgeBoat Logo
|

Informatics Practices

(i) Consider the dataframe "EMP":

        Name    Basic  Da   Hra
E1      Sanya   9500  3000  2000
E2      Krish   7000  5000  1900
E3      Rishav  9650  1500  2100
E4      Deepak  7500  2000  2700
E5      Kriti   9200  1800   500

Give the output

EMP.iloc[1, 2]=8000
EMP.Hra = EMP.Hra + 200
print(EMP)

(ii) Write a Python statement to change the name 'Rishav' to 'Rishab' in the above dataframe.

Or

(Option for part ii only)

Write a Python statement to calculate the sum of Basic, Da, and Hra and assign it to the column 'Salary'.

Python Pandas

1 Like

Answer

Output
      Name  Basic    Da   Hra
E1   Sanya   9500  3000  2200
E2   Krish   7000  8000  2100
E3  Rishav   9650  1500  2300
E4  Deepak   7500  2000  2900
E5   Kriti   9200  1800   700

(ii)

EMP.loc[EMP['Name'] == 'Rishav', 'Name'] = 'Rishab'

Or

(Option for part ii only)

EMP['Salary'] = EMP['Basic'] + EMP['Da'] + EMP['Hra']
Output
      Name  Basic    Da   Hra  Salary
E1   Sanya   9500  3000  2200   14700
E2   Krish   7000  8000  2100   17100
E3  Rishab   9650  1500  2300   13450
E4  Deepak   7500  2000  2900   12400
E5   Kriti   9200  1800   700   11700

Answered By

2 Likes


Related Questions