Skip to content

Instantly share code, notes, and snippets.

@javieroot
Forked from Fhernd/ordenar-datos.py
Created August 8, 2019 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javieroot/4181314e852cc01931c9697fcb6a12d6 to your computer and use it in GitHub Desktop.
Save javieroot/4181314e852cc01931c9697fcb6a12d6 to your computer and use it in GitHub Desktop.
Ordenar datos de un DataFrame en Python.
import pandas as pd
df = pd.DataFrame({'uno': [1, 2, 3], 'dos': [4, 5, 6], 'tres': [7, 8, 9]}, index=['x', 'y', 'z'])
print(df)
print()
# Orden por índice (fila):
print(df.sort_index())
print()
# Ordenar por índice (columna):
print(df.sort_index(axis=1, ascending=False))
print()
# Ordenar por los valores de la columna 'tres':
print(df.sort_values(by='tres', ascending=False))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment