Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created January 31, 2018 00:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Fhernd/cbbf973bc10a67f2a0811ef87f10aad5 to your computer and use it in GitHub Desktop.
Save Fhernd/cbbf973bc10a67f2a0811ef87f10aad5 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