我有一个如下所示的数据框:
import pandas as pd
Z = pd.DataFrame({'Product': ['Apple', 'Apple', 'Apple', 'Orange', 'Orange], 'Selling Price': [1.1, 1.2, 1.3, 2.1, 2.2]})
有数千种独特的产品和数亿的售价。我如何有效地报告每种独特产品的平均售价?
Result = pd.DataFrame({'Product': ['Apple', 'Orange'], 'Average Selling Price': [1.2, 2.15]})
挑战在于数据存储在数百个不同的 .csv 文件中(文件名存储在列表中files),我无法同时将其加载到我的环境中。所以我会做类似的事情
for i in files:
X = pd.read_csv(i)
# add unique products to the data frame Z
# add the sum of their selling prices to Z
# add the number of times the product was sold
# for each unique product, divide the sum of selling prices by the number of times that product was sold
感谢您的任何帮助,您可以提供!
当年话下
相关分类