熊猫对有关索引重复条目的警告
发布于 2021-01-29 18:40:35
在Pandaspivot
方法的文档中,我们具有:
Examples
--------
>>> df
foo bar baz
0 one A 1.
1 one B 2.
2 one C 3.
3 two A 4.
4 two B 5.
5 two C 6.
>>> df.pivot('foo', 'bar', 'baz')
A B C
one 1 2 3
two 4 5 6
我DataFrame
的结构如下:
name id x
----------------------
0 john 1 0
1 john 2 0
2 mike 1 1
3 mike 2 0
我想要这样的东西:
1 2 # (this is the id as columns)
----------------------
mike 0 0 # (and this is the 'x' as values)
john 1 0
但是当我运行该pivot
方法时,它是在说:
*** ReshapeError: Index contains duplicate entries, cannot reshape
这没有意义,即使在示例中,该foo
列上也有重复的条目。我将name
列用作数据透视表的索引,即pivot
方法调用的第一个参数。
关注者
0
被浏览
51
1 个回答