user15605720
user15605720

Reputation:

Int object has not a attribute lower - how to resolve

I'm little confused: Below code is working for my friends, but for me it's not. I've gotten this message:
AttributeError: 'int' object has no attribute 'lower'
This is my code:

data = pd.read_excel(r"C:\Users\admin\Downloads\Bide1n_tweets.xlsx", error_bad_lines=False)
def tokenization(text):
    text = re.split('\W+', text)
    return text
df['Tweet_tokenized'] = df['Text'].apply(lambda x: tokenization(x.lower()))

This is my dataframe

Unnamed: 0  Text
0   0   RT @bennyjohnson: 🚨 BOMBSHELL🚨 \n\nVeteran &am...
1   1   RT @realDonaldTrump: Finally! Suburban women a...
2   2   RT @MaajidNawaz: BREAKING:\nUS Navy veteran Lt.

What should I be doing? Should I put str()?

Upvotes: 0

Views: 1544

Answers (1)

jezrael
jezrael

Reputation: 862406

Convert values to strings:

df['Tweet_tokenized'] = df['Text'].apply(lambda x: tokenization(str(x).lower()))

Or:

df['Tweet_tokenized'] = df['Text'].astype(str).apply(lambda x: tokenization(x.lower()))

Upvotes: 1

Related Questions