Thursday 11 March 2021

Class 12 IP Practical - 11

 11.  WAP in Python to sort the pandas DataFrame on the basis of a single column in ascending order.



 

import pandas as pd

d={'Ritesh':{'English':85,'Bio':82,'Physics':35,'IP':95,'Chemistry':81}, \

   'Rishabh':{'English':55,'Bio':62,'Physics':55,'IP':85,'Chemistry':91}, \

   'Harshit':{'English':65,'Bio':72,'Physics':75,'IP':91,'Chemistry':71}, \

   'Krishan':{'English':25,'Bio':75,'Physics':45,'IP':93,'Chemistry':61}, \

   'Shailesh':{'English':75,'Bio':82,'Physics':65,'IP':97,'Chemistry':51}}

df1=pd.DataFrame(d)

print("DataFrame is:")

print(df1)

print("Sorted DataFrame w.r.t. IP is:")

print(df1.sort_values('Harshit',axis=0))

                                         



 

>>>

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

DataFrame is:

           Ritesh  Rishabh  Harshit  Krishan  Shailesh

English        85       55       65       25        75

Bio            82       62       72       75        82

Physics        35       55       75       45        65

IP             95       85       91       93        97

Chemistry      81       91       71       61        51

Sorted DataFrame w.r.t. IP is:

           Ritesh  Rishabh  Harshit  Krishan  Shailesh

English        85       55       65       25        75

Chemistry      81       91       71       61        51

Bio            82       62       72       75        82

Physics        35       55       75       45        65

IP             95       85       91       93        97

>>>  

No comments:

Post a Comment