python和pandas处理excel(5)
2020-08-29 本文已影响0人
OURPIECE
列、单元格计算
场景1
import pandas as pd
df = pd.read_excel("E:/test.xlsx",index_col='ID')
df['Price']=df['Price1'] * df['Price2'] //列与列的计算
for i in range(4:10):
df.at[i,'Price'] = df.at[i,'Price1'] * df.at[i,'Price2'] //单元格与单元格计算
场景2
import pandas as pd
df = pd.read_excel("E:/test.xlsx",index_col='ID')
df['Price']=df['Price'] + 2 //列与列的计算
df['Price']=df['Price'].apply(lambda x:x+2) //结果同上