There are similar issues asked about (like pandas: iterating over DataFrame index with loc) but I could not find mine. I just do not understand why in pandas
many functionality stops working when index
is added to dataframe
. Like just now I have dataframe
d1
and can do below to add new column:
df4 = df1
df4.loc[df1.crash_type_name == 'pedestrian','Pedestrian_type'] = 1
But the same fails for df2
- same one but index added with df2 = df1.set_index('date_time')
.
The error
IndexingError: (0 False 1 False ....
I know the workaround is to reset_index()
and then to recreate it back, but what is the logic behind index
prohibiting certain operations on dataframe
?