import pandas as pd
def add_2(x):
return x+2
books = pd.read_excel('D:/output.xlsx', index_col='idx')
# 列之间的数值计算1
books['TotalMoney'] = books['SinglePrice'] * 0.8
# 列之间的数值计算2
books['TotalMoney'] = books['SinglePrice'] * books['Discount']
# 列之间的数值计算3
books['SinglePrice'] = books['SinglePrice'] + 2
# 只对某几行进行计算, # 列之间的数值计算4
for i in range(5, 8):
books['TotalMoney'].at[i] = books['SinglePrice'].at[i] * books['Discount'].at[i]
# 列之间的数值计算5
books['SinglePrice'] = books['SinglePrice'].apply(add_2)
# 列之间的数值计算6
books['SinglePrice'] = books['SinglePrice'].apply(lambda x: x+5)
print(books)
books.to_excel('D:/output.xlsx')
视频链接:https://www.bilibili.com/video/av88814463?p=6
来源:oschina
链接:https://my.oschina.net/ski/blog/3179444