1
  • I have read here that pandas indexes are backed by a hash table
  • I also know that hash tables cannot have duplicate keys

So why does the following code work:

pd.DataFrame({'a':['a','a','b'],'b':[1,2,3]}).set_index('a').loc['a',:]

output:
    b
a   
a   1
a   2

figs_and_nuts
  • 4,870
  • 2
  • 31
  • 56
  • I'm guessing whatever is backing it won't have duplicates (or nulls), even though the indexes can be duplicates – sammywemmy Jun 17 '21 at 02:59
  • As noted in the [documentation](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Index.html), an index can be created from any array-like and it has methods to check for duplicates etc. So the direct answer to your question is that index values aren't hash table keys. – Jan Wilamowski Jun 17 '21 at 05:38

0 Answers0