I have a series object w/ following shape
H AB HBP SF G 2B 3B HR BAVG
playerID
ruthba01 2873 8398 43.0 0.0 2503 506 136 714 0.342105
willite01 2654 7706 39.0 20.0 2292 525 71 521 0.344407
gehrilo01 2721 8001 45.0 0.0 2164 534 163 493 0.340082
hornsro01 2930 8173 48.0 0.0 2259 541 169 301 0.358497
I am trying to extract the first column(playerIDs) and convert it to a list. However, list = df['playerID'] gives KeyError, iLoc[0] will return the H column. FYI its a series object.
Thanks
CodePudding user response:
You have the playerID in index
df = df.reset_index()
Then you can call your .iloc
and df['playerID']
Or we do not need reset
l = df.index.tolist()
CodePudding user response:
If that's the index you just need df.index
I believe.