【发布时间】:2018-09-03 22:48:57
【问题描述】:
我正在尝试通过以下数据框在 Dask 上使用 Pivot_table:
date store_nbr item_nbr unit_sales year month
0 2013-01-01 25 103665 7.0 2013 1
1 2013-01-01 25 105574 1.0 2013 1
2 2013-01-01 25 105575 2.0 2013 1
3 2013-01-01 25 108079 1.0 2013 1
4 2013-01-01 25 108701 1.0 2013 1
当我尝试如下pivot_table时:
ddf.pivot_table(values='unit_sales', index={'store_nbr','item_nbr'},
columns={'year','month'}, aggfunc={'mean','sum'})
我收到了这个错误:
ValueError: 'index' must be the name of an existing column
如果我只在索引和列参数上使用一个值,如下所示:
df.pivot_table(values='unit_sales', index='store_nbr',
columns='year', aggfunc={'sum'})
我收到了这个错误:
ValueError: 'columns' must be category dtype
【问题讨论】:
标签: dataframe pivot-table dask