我有一个数据帧,我从中删除了一些行。但是我一直面临的问题是,当我尝试根据索引值遍历数据帧时,由于数据帧中缺少某些索引,它给了我"关键错误!如何遍历数据帧?
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
过滤后必须重置索引:
dataset = dataset[dataset['reviews.rating']!=3].reset_index()