I have a csv file and i already chunked one of the columns in it and wanted to put the result of my chunks into separate columns in the csv file, by converting them into list using this code, but i kept on getting this error
IndexError: list index out of range
tag_count_df = pd.DataFrame(news['entityrecognition'].map(lambda x: Counter(tag[1] for tag in x)).to_list())
Below are my current code,
news=pd.read_csv("news.csv")
news['tokenize'] = news.apply(lambda row: nltk.word_tokenize(row['STORY']), axis=1)
news['pos_tags'] = news.apply(lambda row: nltk.pos_tag(row['tokenize']), axis=1)
news['entityrecog']=news.apply(lambda row: nltk.ne_chunk(row['pos_tags']), axis=1)
tag_count_df = pd.DataFrame(news['entityrecognition'].map(lambda x: Counter(tag[1] for tag in x)).to_list())
news=pd.concat([news, tag_count_df], axis=1).fillna(0).drop(['entityrecognition'], axis=1)
news.to_csv("news.csv")
Sample of my news.csv
ID STORY
1 Washington, a police officer James...
The result i wanted
ID STORY PERSON NE NP NN VB GE
1 Washington, a police officer James... 1 0 0 0 0 1