简体   繁体   中英

Duplicacy in Index of Pandas Series

In Pandas Series, It says that the index values must be unique and a hashable. But when Duplicate Indexes are provided, it still stores both the values, and does not delete the value corresponding to the same index previously, unlike what happens in a Dictionary in Python. Why so? Does it avoid collisions and stores both values corresponding to same Index? Precisely, This is my Code-

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

And the output I get when I print d is-

1    Saurabh
2      Singh
1     Bazzad

index docstring from pandas.Series

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.

As it mentioned there, Non-unique values are allowed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM