开课吧--Python数据分析--第4节 数据七十二变--互动练习:算你狠

题目要求
观察文件(./data/04Books.xlsx)中的商品的单价(OnePrice)和购买数量(Count)
题目讲解
计算出对应的总价(Price)。
书写代码
import pandas

df = pandas.read_excel('./data/04Books.xlsx')

df['Price'] = df['OnePrice'] * df['Count']
# 第一种方法

for i in range(len(df)):
  df["Price"].iloc[i] = df["OnePrice"].iloc[i] * df["Count"].iloc[i]

# 第二种方法

posted @ 2020-09-13 20:32  李思爱学习  阅读(235)  评论(0编辑  收藏  举报