1

I have the below dataframes -

            A          B
one 2014-01-01 2014-02-28
two 2014-02-03 2014-03-01

Now when I try -

df['C'] = df['A'] - df['B']

I get the below result -

            A          B        C
one 2014-01-01 2014-02-28 -58 days
two 2014-02-03 2014-03-01 -26 days

But I want my result to be as below without the 'days' part because I want to export the data into a sql table directly -

        A          B        C
one 2014-01-01 2014-02-28 -58
two 2014-02-03 2014-03-01 -26 

What is the easiest way to get that?

Thanks.

EdChum
  • 376,765
  • 198
  • 813
  • 562
0nir
  • 1,345
  • 4
  • 20
  • 41

1 Answers1

1

Just divide the np.timedelta64 by 1 day:

In [21]:

df['C'] = (df['A'] - df['B'])/(np.timedelta64(1,'D'))
df
Out[21]:
  index          A          B   C
0   one 2014-01-01 2014-02-28 -58
1   two 2014-02-03 2014-03-01 -26

See related: extracting days from a numpy.timedelta64 value

Community
  • 1
  • 1
EdChum
  • 376,765
  • 198
  • 813
  • 562