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.



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation