0

I have a data frame with 5 columns. Two of the columns are of type datetime64[ns], called Start_Time and End_Time.

I wanted to create a new column in my data frame called Overall_Time.

The way I did this was:

df['Overall_Time'] = df['End_Time'] - df['Start_Time']

However, I get this message:

C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:1: 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: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  """Entry point for launching an IPython kernel.

So I tried this way:

df['Overall_Time'] = df.loc[:,'End_Time'] - df.loc[:,'Start_Time']

But get the same message as the first time.

So the problem is, it does create that new column in df but the message suggest that its copying (?) so I try using .loc and still says the same thing... so how can I use .loc so that I dont get this message: A value is trying to be set on a copy of a slice from a DataFrame. Any suggestions?

Thanks!

Nelly Yuki
  • 399
  • 1
  • 4
  • 16

0 Answers0