2022-06-17

Python Pandas: Insert Count of words - Error A value is trying to be set on a copy of a slice from a DataFrame

I'm trying to insert a field with the number of words of a text (complaint), with the following:

df['Avg_length'] = df["complaint"].apply(lambda x: len(x.split()))

But got the error:

A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead

I had tried to use loc but another error shows, I don't get why is an error in my sentence.



No comments:

Post a Comment