Another easy SettingWithCopyWarning

Screen Link:

My Code:

I have reviewed all the posts that refer to this problem, even the explanation that DQ has in relation to this problem I have read it coming to a point of zero ideas.

autos["date_crawled"] = autos["date_crawled"].str[:10].copy()

What I expected to happen:

slice this 2016-03-26 17:47:46 data and re-asign again into autos["date_crawled"] in this format 2016-03-26

What actually happened:

I get solution BUT still the warning so this is not aver nice practice

/dataquest/system/env/python3/lib/python3.4/site-packages/ipykernel/ 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

See the caveats in the documentation: if __name__ == '__main__':

What I did?

`autos.loc["date_crawled"] = autos.loc["date_crawled"].str[:10]`
`autos.iloc[:,0] = autos.iloc[:,0].str[:10]`
`A = autos["date_crawled"].str[:10]`
`autos.loc["date_crawled"] = A.copy()`

The idea, as the dq document says, is to recognize chained indexing and avoid it at all costs, but so far I don’t see it.

Again thousan times thx


Is the autos a dataframe you get by reading in the .csv file as it is? Or have you done some transformation like autos = autos[boolean_mask]?

1 Like


I’ve done something but I’m not sure to answer you in a precise way

I want to send you the file so I don’t make you dizzy.

I would say that all the time I am with the original csv but as I say I prefer that you take a look at the document and so we just confirm it, I am not 100% sure.

Challengue.ipynb (275.3 KB)



Click here to view the jupyter notebook file in a new tab

Ok, I´ve got two pieces of news: a good and a bad one :joy:
The good one - I found where you have to set a copy in order to avoid further SettingWithCopyWarning. The cell In [43] :

autos = autos[autos["price_Dollars"].between(2,3890000)]

If you set copy (.copy()) here, then it won’t raise warning later on.

The bad one - I´m really confused why it causes SettingWithCopyWarning in your project and it doesn´t in mine, although I used the same technique to deal with price outliers. I even tried a piece of my code which creates a new column in your project and it raised the Warning while it works perfectly fine in my project :woman_shrugging:

1 Like

Hats off! :tophat:

Two days later good news is good news, the truth is that I would never have gotten there.

The one that is not so good is indeed more strange because I downloaded the work of a girl who did that movement of copying the dataframe on itself and did not give any alert.(!) :thinking:

While I am writing these words I will export the csv online from the platform (hope works) and work locally on mine anaconda that I have here to see how it behaves. :crossed_fingers:

Another thing in case it doesn’t work will be to compare with the girl’s work what steps she took and I didn’t, basically to rule out.

I thank you for the work you have done, if I could do more than give you a :hearts:I would invite you for a :coffee:

Thanks again for the analysis, you have helped me a lot,


1 Like

You are welcome!
I understand you what a relief to get the solution after 2 days of struggling :grinning:

1 Like

Yes, you got it right.

The sun is shining again. :sunglasses:

I hope I can help you next time, it will be a good sign.

Thank you.


1 Like