Pandas系列指数的重复性

2024-09-19 23:41:14 发布

您现在位置:Python中文网/ 问答频道 /正文

在Pandas系列中,它指出索引值必须是唯一的并且是可散列的。但是,当提供了重复索引时,它仍然存储这两个值,并且不会删除以前与同一索引对应的值,这与Python中字典中发生的情况不同。为什么会这样?它是否避免了冲突并存储了对应于同一索引的两个值? 准确地说,这是我的密码-

d=pd.Series(['Saurabh','Singh','Bazzad'],[1,2,1])

当我打印d时得到的输出是-

1    Saurabh
2      Singh
1     Bazzad

Tags: 密码pandas字典情况seriespdsinghsaurabh
1条回答
网友
1楼 · 发布于 2024-09-19 23:41:14

index来自pandas.Series的docstring

index : array-like or Index (1d)
    Values must be hashable and have the same length as `data`.
    Non-unique index values are allowed. Will default to
    RangeIndex (0, 1, 2, ..., n) if not provided. If both a dict and index
    sequence are used, the index will override the keys found in the
    dict.

如前所述,允许使用非唯一值

相关问题 更多 >