1

I'm trying to concatenate two columns (string) into a new one but Pandas is returning a warning

I have a main dataframe called destaques, with two columns: sub_type and category (and a few others but they arent needed)

Then I'm trying to concatenate them into a new column called sub_type_cat

destaques['sub_type_cat'] = destaques['sub_type']+'_'+destaques['category']

The issue is that i'm receiving a warning message for this operation.

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

I did some research and understood that this is not an error, its a warning message saying that Pandas may or may not do the correct operation. It seems it is working, but I dont want to bet my work in luck. For setting values into an existing column it is solved by using .loc or .iloc, but my problem is that I want to create a new column, not only set values on an existing column.

mateusvl
  • 131
  • 12

0 Answers0