import pandas as pd
import numpy as np
#导入数据
df =pd.read_csv('./csv_data/households.csv')
#按区间切分进行分组
listBins = [0, 30000, 60000, 100000, 10000000]
#设置切分后对应的标签
listLabels= [1,2,3,4]
#利用pd.cut进行数据离散化切分
df['fenzu'] = pd.cut(df['income'],bins = listBins,labels = listLabels ,include_lowest=True)
df.to_csv('./household_transition_fenzu.csv')
df.head()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)