I have an initial time value like 15:59:26.186000 (format %H:%M:%S.%f).
And a pandas DataFrame with a seconds as floats
SECONDS
0.44121
0.92844
1.60995
2.16770
2.87059
Is there any way to add those seconds to the initial value? So first row would be 15:29:26.627, etc.
You can use pd.to_timedelta to convert the Series to a delta, and add it to a datetime version of the initial value:
s = pd.Series([0.44121, 0.92844, 1.60995, 2.16770, 2.87059])
t = '15:59:26.186000'
pd.to_timedelta(s, unit='s') + pd.to_datetime(t, format='%H:%M:%S.%f')
You can use pd.to_timedelta with unit to convert SECONDS to time and add:
df['SECONDS'] = pd.Timedelta('15:59:26.186000') + pd.to_timedelta(df['SECONDS'], unit='s')
You can also multiply:
df['SECONDS'] = pd.Timedelta('15:59:26.186000') + df['SECONDS'] * pd.Timedelta('1s')
Output:
SECONDS
0 0 days 15:59:26.627210
1 0 days 15:59:27.114440
2 0 days 15:59:27.795950
3 0 days 15:59:28.353700
4 0 days 15:59:29.056590