Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Error in removing punctuation: 'float' object has no attribute 'translate'

user7631183:

I am trying to remove punctuations from a col in a data frame by doing the following:


def remove_punctuation(text):
return text.translate(table)

df['data'] = df['data'].map(lambda x: remove_punctuation(x))

But I am getting the following error:

'float' Object has no attribute 'translate'

I checked the dtype of the col as in here:


from pandas.api.types import is_string_dtype
is_string_dtype(df['data'])

and got the following output:

True

I am not sure what's going wrong in here?

I have also tried the following: translator = str.maketrans('', '', string.punctuation)


def remove_punctuation(text):
return text.translate(translator)
df['data'] = df['data'].map(lambda x: remove_punctuation(x))

but I am still getting the same error



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Error in removing punctuation: 'float' object has no attribute 'translate'

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×