Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created January 31, 2018 19:36
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 Fhernd/a26272b522557b606cbeb9e1b944e5da to your computer and use it in GitHub Desktop.
Save Fhernd/a26272b522557b606cbeb9e1b944e5da to your computer and use it in GitHub Desktop.
Aplica una función a un conjunto de datos en Python.
import pandas as pd
import numpy as np
df = pd.DataFrame({'uno': [1, 2, 3], 'dos': [4, 5, 6], 'tres': [7, 8, 9]}, index=['x', 'y', 'z'])
# Eleva al cuadrado todos lo elementos:
print(df.applymap(lambda x: x*x))
print()
# Triplica los elementos de la columna 'dos':
print(df['dos'].map(lambda x: 3 * x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment