pandas数据清洗:http://www.it165.net/pro/html/201405/14269.html
data=pd.Series([1,2,3,4])
data.replace([1,3], np.nan)#一次替换多个,可以传入一个由待替换值组成的列表以及一个替换值:
#传入的参数也可以是字典: data.replace({4: np.nan, 2: 111})
贴吧爬取得数据,vehicle字段需要处理一下,即把vehicle字段的某些值做下替换:
1 import pandas as pd 2 import numpy as np 3 data=pd.read_excel("ysu_new.xlsx",sheetname="sheet1") 4 data["vehicle"]=data["vehicle"].str[0:-1] 5 data["vehicle"]=data["vehicle"].replace({"":"web端","1":"手机贴吧","4":"手机贴吧","phone":"手机贴吧"}) 6 # print(data.head(10)) 7 data.to_excel("output.xlsx")