import pandas
sub_info = pandas.read_csv("contract.csv")
#sub_info
#print (sub_info)
type(sub_info)
#print (sub_info.dtypes)
first_rows = sub_info.head(1)
#print (first_rows)
#print (sub_info.columns)
#print (sub_info.shape)
#print (sub_info.loc[1])
sub_info.loc[0:3]
two_five_nine = [2,5,9]
sub_info.loc[two_five_nine]
id1 = sub_info["CONTRACTID"]
id1
str1 = ["CONTRACTID","STATUS"]
id2 = sub_info[str1]
id2
sub_info.columns
columns_list = sub_info.columns.tolist()
time_list = []
for i in columns_list:
if i.endswith("TIME"):
time_list.append(i)
time_info = sub_info[time_list]
is_value_empty = time_info.isnull()
is_value_empty
time_info.fillna("0")
#用前一个数据代替NaN:method=‘pad‘
time_info.fillna(method=‘pad‘)
#与pad相反,bfill表示用后一个数据代替NaN
time_info.fillna(method=‘bfill‘)
#用limit限制每列可以替代NaN的数目
time_info.fillna(method=‘bfill‘,limit=1)
#使用平均数代替NaN
time_info.fillna(time_info.mean())
#指定列 数据代替NaN
time_info.fillna(time_info.mean()[‘SUBTIME‘:‘OPRTIME‘])
原文地址:http://blog.51cto.com/devops2016/2074311