Home > front end >  how to do addition dataframe of different type of TImestamp columns in python
how to do addition dataframe of different type of TImestamp columns in python

Time:09-17

below is my dataframe and I want to do an addition operation which i have mentioned down.

a                            b
0 days 19:18:43.997000       4
0 days 19:18:44.039000       4

b is a result of df['time:timestamp'].dt.dayofweek.

when i do following code df['a'] (df['b'] * 3600 * 24), it throws TypeError: Addition/subtraction of integers and integer-arrays with TimedeltaArray is no longer supported. Instead of adding/subtracting n, use n * obj.freq

type of a -: Timedelta('0 days 19:18:43.997000')

type of b -: numpy.int64

can someone help me with this?

CodePudding user response:

You need to convert b back to timedelta:

df['a']   pd.to_timedelta(df['b'], unit='d')

Or

df['a']   df['b'] * pd.Timedelta('1D')

Output:

0   4 days 19:18:43.997000
1   4 days 19:18:44.039000
dtype: timedelta64[ns]
  • Related