I saw this code in someone's iPython notebook, and I'm very confused as to how this code works. As far as I understood, pd.loc[] is used as a location based indexer where the format is:
df.loc[index,column_name]
However, in this case, the first index seems to be a series of boolean values. Could someone please explain to me how this selection works. I tried to read through the documentation but I couldn't figure out an explanation. Thanks!
iris_data.loc[iris_data['class'] == 'versicolor', 'class'] = 'Iris-versicolor'
解决方案
pd.DataFrame.loc can take one or two indexers. For the rest of the post, I'll represent the first indexer as i and the second ind