'change value in pandas dataframe using iteration

I have a training data set of the following format:

print(data.head(5))
#Output



           0  1
0  a b c d e  1
1  a b c d e  1
2  a b c d e  1
3  a b c d e  1
4  a b c d e  1

It is a text classification task and I am trying to split the text "a b c d e" in to a Python list. I tried iteration:

data #the dataset
len_data = len(data)
for row_num in range(len_data):
    data.loc[row_num, 0] = data.loc[row_num, 0].split(" ")

However this doesn't work and returned the error Must have equal len keys and value when setting with an iterable. Could someone help me with this problem? Many thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source