Reputation: 11
I have a dataframe from which i have deleted some rows. But the problem i have been facing is when i try to loop through dataframe on the basis of index values it gives me 'key error!' due to some indices are missing from the dataframe. How to loop through the dataframe?
dataset =pd.read_csv('sentimentAnalysis.csv') # dataset imported
dataset = dataset[dataset['reviews.rating']!=3] #dropped the rows which
contain ratings =3
for i in range[0,5000]: #encounter error at i = 222 cause that row is missing due to the previous line of code
#XXXXXXXXXXXXXXXXXXX
Upvotes: 1
Views: 370
Reputation: 42916
You have to reset your index after filtering:
dataset = dataset[dataset['reviews.rating']!=3].reset_index()
Upvotes: 1