pandas操作excel操作-05-批量数据操作

百般思念 提交于 2020-02-29 13:43:26
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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!