-1

I have a data frame:

                score            created_at 
0                0.00   2021-04-04 08:28:08       
1                0.25   2021-04-04 08:18:03      
2               -0.20   2021-04-04 08:09:54   
3                0.15   2021-04-03 06:08:55      
4                0.19   2021-04-03 06:08:55

I want to set the format of the column create_at to datetime by using:

df['created_at']=pd.to_datetime(df['created_at']) 

but I get the copy warning below:

C:\Anaconda\lib\site-packages\ipykernel\__main__.py:30: 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

Can I use in_place=True somewhere? How do I fix so the warning message goes away?

halfer
  • 19,824
  • 17
  • 99
  • 186
Stacey
  • 4,825
  • 17
  • 58
  • 99
  • btw It's a warning you can ignore it or have a look at [how-to-deal-with-settingwithcopywarning-in-pandas](https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas) – Anurag Dabas Jul 10 '21 at 14:33
  • 1
    The confusion with these types of errors is that this is an error that is raised when _setting_ to a copy of a slice. That means _before_ this line (the one that raised the error), the dataframe was _already_ a copy of a slice. You should look at your code before this line to determine where you've unsafely subset the dataframe. – Henry Ecker Jul 10 '21 at 15:27
  • Thanks Henry - I hadn't set the dataFrame correctly above – Stacey Jul 10 '21 at 17:42

1 Answers1

0

So the df here is subset of another df , when you slice it adding copy

df = somedf[cond].copy()
BENY
  • 317,841
  • 20
  • 164
  • 234