Created
February 8, 2017 02:56
-
-
Save Keiku/b1e3837eb3ce104508637eeaf2e22862 to your computer and use it in GitHub Desktop.
Cut a variable with pandas.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from sklearn import datasets | |
iris = datasets.load_iris() | |
iris_df = pd.DataFrame(iris.data, columns=iris.feature_names) | |
iris_df['species'] = iris.target | |
mapping = {0 : 'setosa', 1: 'versicolor', 2: 'virginica'} | |
iris_df = iris_df.replace({'species': mapping}) | |
iris_df['sepal length (bins)'] = pd.cut(iris_df['sepal length (cm)'], bins=[0, 3, 6, 9], include_lowest=False, right=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment