学习笔记侵权删
pandas求累积值
chengji=[[100,95,100,99],[90,98,99,100],[88,95,98,88],[99,98,97,87],[96.5,90,96,85],[94,94,93,91]]
data=pd.DataFrame(chengji,columns=['语文','类别','数学','政治'])
data['合计']=data.apply(lambda x: x.sum(),axis=1)
print('合计',data)
data.loc['小计']=data.apply(lambda x: x.sum(),axis=0)
print('小计',data)
data['累加值']=0
data.drop('小计',inplace=True)
print('删除小计',data)
data.sort_index(inplace=True)
print('重排序列',data)
data.astype(float)
data['累加值']=data['合计'].cumsum()
print('累计data',data)
data.sort_values(by=['合计','语文'] , ascending=[False,False],inplace=True)
data['排名']=data['合计'].rank(ascending=0,method='min')
print (data)
data.sort_index(inplace=True)
print(data)
data = data.reset_index(drop=True)
data.loc[1:3,'语文']=""
data.loc[4,'语文']=None
print(data)
print(data.dtypes)
data.fillna(value=0,inplace=True)
print('填充缺失值',data)
data.replace("",0,inplace=True)
print('填充空值',data)
print(data.loc[data.index==1,'累加值'])
print('类别数量',data['类别'])
print('类别=95',data.loc[data['类别']==95,'累加值'])
print(data.loc[:,'合计']-data.loc[:,'语文'])