EBAY Additional Steps

Doing the additional steps in Ebay Car sales, unable to save output from code below into dataframe, I receive SettingWithCopyWarning


Require some feedback please


Hi @neilgordonwalker

you may try either of the two options:

  1. auto["unrepaired_damage"] = auto.loc[:,"unrepaired_damage"].map(damage_dict)

  2. auto["unrepaired_damage"] = auto["unrepaired_damage"].map(damage_dict)

please do note that the “map” method, would make anything other than the two values specified in “damage_dictionary” as NaN.

you may try the “replace()” method in case you want to avoid the other values being changed to NaN

Hello thanks for your reply, i have tried both your suggestions previously and received the following error. I will try the replace method, the instructions were to map the new values…

**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

Hi @neilgordonwalker

try this once:

auto = auto.copy()

auto[column] = auto[column].map(dict)

the “.copy()” might have been taken up in a later course by DQ.

if this still doesn’t work could you upload/ uplink your project screen here?


Hello Rucha

Thanks for your help, the auto.copy() did the trick, however as map overwrites any values if the key is not in the dictionary , I will use replace instead, however this looks a mess, I would like to put the key/values for each column in a dictionary and then run the replace method just once…

auto[‘unrepaired_damage’] = auto[‘unrepaired_damage’].str.replace(‘nein’,‘no’).str.replace(‘ja’,‘yes’)

Hi @neilgordonwalker

No need to do all that. Just make sure the dictionary has all the values from the series/column along with their replacements to use “.map()” method.

Before applying map, I did a “.unique()” for the series/column, then made a dictionary out of that.

If you wish to test with replace as well, then simply use “.replace()” method with dictionary just like you would with “.map()”

Read the pandas documentation for replace() method. It allows us to use dictionary.


hope it helps.