guopengfa
发布于 2020-05-08 / 589 阅读 / 0 评论 / 0 点赞

pandas类似excel数据透视的函数功能

import pandas as pd
import numpy as np
import time

if name == 'main':
time0 = time.time()
data1 = pd.read_csv("合拼后的国内仓30天销量,不除大单2_2020-04-27_06_48_13_41171152bt.csv")
data2 = pd.read_csv("合拼后的国内仓30天销量,不除大单2_2020-04-29_06_41_18_40754752bt.csv")
data = pd.concat([data1,data2],axis=0)
data = data.groupby([data.付款日期,data.sku]).agg({"SKU销量":"sum"})
data.reset_index(inplace = True)
data = data.pivot_table(index="sku",columns="付款日期",aggfunc={"SKU销量":np.sum},margins=False,fill_value=0)
data.to_csv("销量透视.csv")
print("计算完成,用时%s秒"%(time.time()-time0))


评论