import pandas a=pandas.read_excel(r'D:scrapy网络爬虫 ba.xlsx') bins=[0,5000000,max(a['Salary'])] group_by=['底','高'] a['new_col']=pandas.cut(a['Salary'],bins,labels=group_by) a=a.fillna(axis=1,method='ffill') #从纵向来看,用前一个值填充空值 print(a)
import pandas a=pandas.read_excel(r'D:scrapy网络爬虫 ba.xlsx') bins=[0,5000000,max(a['Salary'])] group_by=['底','高'] a['new_col']=pandas.cut(a['Salary'],bins,labels=group_by) a=a.fillna(axis=1,method='ffill') #从纵向来看,用前一个值填充空值 print(a)