Chris Kouts
Chris Kouts

Reputation: 91

Pandas .loc[] returning another data frame

How do I get the actual string variable instead another for text processing?

df.columns
df.head(3)

Returns

Index(['text', 'is_spam'], dtype='object')

779     Subject re a note being sent out under john s...    False
1552    Subject hi mind opt in referencement from h...  True
2341    Subject ilug do not drop your life insurance... True

Now trying to access the actual string I have:

string = df.loc[[i],['text']] # i is valid integer index
print(type(string))

Returns

<class 'pandas.core.frame.DataFrame'>

How can I select the actual string variable? such that I can perform string operations.

Upvotes: 0

Views: 121

Answers (1)

Krzysztof Chojnacki
Krzysztof Chojnacki

Reputation: 115

 string = df.loc[i, 'text']

Use code above instead of yours

Upvotes: 1

Related Questions