Skip to content

Instantly share code, notes, and snippets.

@glamp
Created February 17, 2013 18:29
Show Gist options
  • Select an option

  • Save glamp/4972664 to your computer and use it in GitHub Desktop.

Select an option

Save glamp/4972664 to your computer and use it in GitHub Desktop.
import pandas as pd
from sklearn.datasets import load_iris
iris = load_iris()
df = pd.DataFrame(iris.data, columns=iris.feature_names)
# apply
cols = df.columns[0:4]
# divide each numeric column by 2
df[cols].apply(lambda x: x / 2).head()
# divide 1 column by 2
df.sepal_length_cm.apply(lambda x: x / 2).head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment