Advertisement
elena1234

sort dataframe in Python

Apr 24th, 2022 (edited)
1,149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | Source Code | 0 0
  1. import pandas as pd
  2.  
  3. df = pd.DateFrame(people)
  4. print(df.sort_values(by=['last', 'first'], ascending = [False, True]).reset_index(drop = True))
  5. # OR (they are equal)
  6. print(df.sort_values(by=['last', 'first'], ascending = [False, True], ignore_index = True))
  7.  
  8. ############################################
  9. mpg.sort_values(ascending = False, inplace = True)
  10. mpg.sort_index(inplace = True)
  11.  
  12. ############################################
  13. titanic.nlargest(n = 5, columns = 'fare')
  14. titanic.nsmallest(n = 5, columns = 'fare')
  15. cars.nlargest(n = 10, columns = "weight")
  16.  
  17. ############################################
  18. top_20_percent = df.nlargest(int(len(df) * 0.2), columns='column_name')
  19.  
  20. ############################################
  21. titanic.loc[titanic.age.idxmin()]
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement