我有一个带有列year
,month
,source
。。。每个(年、月、源)有多个记录,我需要生成一个透视表,其索引是(年、月),源是列,每个(年、月、源)记录的计数是值。我有以下代码
df.privot_table(index = ['year','month'], columns = ['source'], aggfunc = np.size, fill_value = 0)
我的数据是这样的
2001,02,A, ....
2001,02,A,....
2001,03,B,....
2001,03,B,....
2001,03,B,....
这就是我想要的数据
A B
2001, 02, 2, 0
2001, 03, 0, 3
但它会抛出以下错误消息
Reindexing only valid with uniquely values index objects
怎么了?你知道吗
通过使用
aggfunc=len
可以达到所需的输出。你知道吗相关问题 更多 >
编程相关推荐