loc on Series returning scalar when result size is 1 #31381
Labels
Duplicate Report
Duplicate issue or pull request
Indexing
Related to indexing on series/frames, not to indexes themselves
Code Sample
Calling
.loc
when the result length is 2 returns a Series (as expected):Output:
Calling
.loc
when the result length is 1 returns astr
:Output:
Problem description
The fact that the same code returns different types causes inconsistencies. If I run
len
on the result, I would get 2 forid=3
and 5 forid=1
orid=2
, since the string length is 5:Output:
When calling
loc[1]
:Output:
Expected Output
.loc
should return a Series regardless of the size. Otherwise this causes bugs when trying to evaluate the length of the output.Output:
Output:
Output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: