當前位置:成語大全網 - 新華字典 - python DataFrame列運算

python DataFrame列運算

import pandas as pd

#新建壹個dataFrame,df

d={

'消費總金額':[100,150,200],

'消費次數':[1,2,2],

}

df=pd.DataFrame(d)

#新增壹列‘平均值’表示兩者相除

df['平均值'] =df.apply(lambda x: x[0] / x[1], axis=1)

df