when processing a pandas.df with for loop.I usually meet up with errors. When the error has been removed, I will have to restart the for loop form the beginning of the dataframe. How can I start the for loop from the error position, getting rid of run it repeatedly. For example:
senti = []
for i in dfs['ssentence']:
senti.append(get_baidu_senti(i))
in the code above, I'm trying to do the sentiment analysis through api and store them into a list.However, the api only input GBK format whereas my data are encoded in utf-8. So it usually meet up with errors like this:
UnicodeEncodeError: 'gbk' codec can't encode character '\u30fb' in position 14: illegal multibyte sequence
So I have to delete the specific items like'\u30fb' manually and restart the for loop. At this time, the list"senti" contains so many data already so I don't want to abandon them. What can I do to improve the for loop?