Thursday 11 March 2021

Class 12 IP Practical - 19

 

19. WAP in Python to create a the following DataFrame –

 

Population

Hospitals

Schools

Delhi

10927986.0

189.0

7916.0

Mumbai

12691836.0

208.0

8508.0

Kolkata

46192.0

149

7226.0

Chennai

4328063.0

157

7617.0

Banglore

5678097.0

1200.0

1200.0

Create another DataFrame from the above DataFrame which not contains column ‘Population’ and raw Banglore.


import pandas as pd

d={'Population':{'Delhi':10927986.0,'Mumbai':12691836.0,'Kolkata':46192.0, \

                 'Chennai':4328063.0,'Banglore':5678097.0}, \

   'Hospitals':{'Delhi':189.0,'Mumbai':208.0,'Kolkata':149,'Chennai':157,'Banglore':1200.0}, \

   'Schools':{'Delhi':7916.0,'Mumbai':8508.0,'Kolkata':7226.0, \

                 'Chennai':7617.0,'Banglore':1200.0}}

Df=pd.DataFrame(d)

print("DataFrame is : ")

print(Df)

Df1=Df.drop(index='Banglore', columns='Population')

print("Updated DataFrame: ")

print(Df1)

 

 

 

>>>

======================= RESTART: C:/Program Files (x86)/Python38-32/IP-19.py ======================

DataFrame is :

          Population  Hospitals  Schools

Delhi     10927986.0      189.0   7916.0

Mumbai    12691836.0      208.0   8508.0

Kolkata      46192.0      149.0   7226.0

Chennai    4328063.0      157.0   7617.0

Banglore   5678097.0     1200.0   1200.0

Updated DataFrame:

         Hospitals  Schools

Delhi        189.0   7916.0

Mumbai       208.0   8508.0

Kolkata      149.0   7226.0

Chennai      157.0   7617.0

>>> 

 








No comments:

Post a Comment