Skip to content
Advertisement

Using Pandas df.loc

I have a DataFrame of a csv file which is being read by pandas. What I am attempting to do is use df.loc to add a new column but only insert values into the column when values from another column, called “SKU” end with “-RF” and “-NEW”.

The code I was working on is below. It has the csv file being read, “original_file”, and then two .loc commands. ONE new column called “Cond” is supposed to be being added, and I want “NEW” to be added to that column where the value in the ‘SKU’ column ends with “-NEW” and “USED” to be added to the new column where the ‘SKU’ ends with “-RF”.

AttributeError: ‘list’ object has no attribute ‘str’

This is the error I have been getting on it.

JavaScript

Advertisement

Answer

Try with adding the df when you call column by name

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement