Problems with loc function in python, doesn't find a label taht is in my dataframe

37 Views Asked by At

I have an issue with using the 'loc' function in Python. I would like to extract a specific row from my dataframe 'df', which contains movie titles along with their respective information. The problem is that when I use 'df.loc['movie title']', I receive the following error as if it doesn't exist in the DataFrame, even though it does. Let me show you an example:

df.set_index('title')

And here i receive the correct output

enter image description here

as you can see Toy Story in in DataFrame df but when i try to print all his rae with loc i receive this error: enter image description here

I use pd.loc['Toy Story'] but python say that in my df there isn't any 'Toy story' label Can someone give me an explanation of this?

1

There are 1 best solutions below

1
Jeril On

You need to save the changes to the dataframe. Can you try the following:

df = df.set_index('title')