【发布时间】:2017-07-24 21:56:41
【问题描述】:
有这样的数据框:
>>> df = pd.DataFrame({'name': ['foo', 'foo', 'bar', 'bar'],
'colx': [1, 2, 3, 4],
'coly': [5, 6, 7, 8]})
>>> df.set_index('name', inplace=True)
>>> df
colx coly
name
foo 1 5
foo 2 6
bar 3 7
bar 4 8
如何获得正确格式的索引,例如:
colx coly
name
foo 1 5
2 6
bar 3 7
4 8
这样 pandas 就不会抱怨重复索引。
【问题讨论】:
标签: python python-3.x pandas dataframe