DS_Tn
DS_Tn

Reputation: 27

how i can iterate over a column (type : series)

i want to iterate over rows of a column (type : series), each row represents a series of words, and i want to classify each word.

examples of some rows:

['hard', 'house', 'warm', 'lovely']


['beauty', morning', 'work', 'sick']

i have the following code :

for i, row in df['splitsent'].items(): 

    test=i['splitsent']

i get this error :

' test_set=i['stoplist']


TypeError: 'int' object is not subscriptable '

Upvotes: 0

Views: 128

Answers (2)

BENY
BENY

Reputation: 323366

This is iterrows

for x , y in df.iterrows(): 

    print(x)#index
    print(y)#serise row

If that is series

for x,y in zip(df.index,df.Value):#df.Value.iterrows()
    print(x)#index
    print(y)#value

Upvotes: 1

Mark Bailey
Mark Bailey

Reputation: 1675

row is the data. i is the integer index: 0, 1, 2, ... so

i['splitsent']

does not make sense for an integer, i.

Upvotes: 0

Related Questions