1.在df的索引’Salary’左侧插入索引’low-salsary’并赋值
col_name = data.columns.tolist()
col_name.insert(col_name.index('Salary'),'low_salary')
df = df.reindex(columns=col_name)
df['low_salary'] = low_list
2.将索引名’Salary’:改为’high_salary’并赋值
df.rename(columns={'Salary': 'high_salary'},inplace=True)
df['high_salary'] = high_list
3.自定义删除函数
def drop_eduyc(df,columns): # 利用drop方法将colums='educationBackground'中含有'招'字的行删除
cols = [x for i, x in enumerate(df.index) if u'招' in df.loc[i, columns]]
# 利用enumerate对columns进行遍历,将colums='educationBackground'中含有'招'字的educationBackground放入cols中
df.drop(cols, axis=0,inplace=True)#删除含有‘招’字的行
drop_eduyc(data, 'educationBackground')#调用函数