I'm trying to filter a df column and rename certain rows depending on next/previous row value.
This code (without AND though) worked for me for other sorting in the same df:
for row in df.index:
if df['col1'][row] == 'b' and df['col1'][row+1] =='name':
df['col1'][row +1] = 'name1'
df['col1'][row +2] = 'name2'
Here it throws KeyError 9 and I assume it's because of AND condition in row+1. Is there any way to workaround?

Aucun commentaire:
Enregistrer un commentaire