0

When I look at the answer to a similiar question as shown in this link: Pandas: adding column with the length of other column as value

I come across an issue where the solution its suggesting i.e

df['name_length'] = df['seller_name].str.len()

Throws the following warning

'''
SettingWithCopyWarning: 
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
'''

My question is: How could this be done inorder to prevent this warning from occuring? As in this command I would like to add a new column to the original dataframe not create some sort of copy of a slice.

Curious
  • 325
  • 1
  • 10

1 Answers1

0

I took a sample data set to test this issue in Python 3.8

Sample data enter image description here

here is the same code which you ran df['name_length'] = df['seller_name'].str.len()

there was no error enter image description here

Vivs
  • 447
  • 4
  • 11