统计销量 Counter

来源:互联网 发布:高中编程 编辑:程序博客网 时间:2024/04/29 13:19
import pandas as pdfrom collections import Counterimport numpy as npdf = pd.read_csv("fb_viogi.csv",encoding="gbk")ebaynos = df.ebayno.valuesitem = Counter(ebaynos) #返回的是字典 #list中出现个数统计result = []for ebayno in item.keys():    sub_df = df[df.ebayno == ebayno]    title = sub_df.title.values[0] #选择第一个title    price = sub_df.price    mean = round(price.mean(),2) #计算平均价格,并四舍五入保留2位小数    result.append([ebayno,title , item[ebayno], mean])re = pd.DataFrame(result, columns=["ebayno","title","sale","price"])re.to_csv("result_sale.csv", index= False)

原创粉丝点击