Advertisement
Fhernd

ordenar-datos.py

Jan 30th, 2018
852
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. df = pd.DataFrame({'uno': [1, 2, 3], 'dos': [4, 5, 6], 'tres': [7, 8, 9]}, index=['x', 'y', 'z'])
  4.  
  5. print(df)
  6.  
  7. print()
  8.  
  9. # Orden por índice (fila):
  10. print(df.sort_index())
  11.  
  12. print()
  13.  
  14. # Ordenar por índice (columna):
  15. print(df.sort_index(axis=1, ascending=False))
  16.  
  17. print()
  18.  
  19. # Ordenar por los valores de la columna 'tres':
  20. print(df.sort_values(by='tres', ascending=False))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement