Reputation: 3
I have a dataframe where my index is an elapsed seconds series.
Depth_m | Temperature_degC | Salinity_PSU | OBS S9604_mV | OBS highsens S9604_mV | OBS S9602_mV | OBS S9603_mV | Time elapsed_sec
0.00 | 35.687 | 28.9931 | 36.7530 | 0.0082 | 0.0024 | 0.0059 | 0.0120
0.25 | 35.684 | 28.9932 | 36.7531 | 0.0083 | 0.0026 | 0.0060 | 0.0106
0.50 | 35.687 | 28.9931 | 36.7532 | 0.0079 | 0.0021 | 0.0055 | 0.0099
0.75 | 35.687 | 28.9931 | 36.7532 | 0.0305 | 0.0075 | 0.0056 | 0.0101
I would like to calculate create a new series obtained from a start time and elapsed seconds. I am using python v 2.7 with pandas. Do any of you know how to obtain that? Thanks
Upvotes: 0
Views: 490
Reputation: 313
That should do the trick
from __future__ import print_function, division
import pandas as pd
start_time = 14
data = pd.read_csv('data.txt', sep="|", header=0, skip_blank_lines=True)
data['Time'] = pd.Series(data[' Time elapsed_sec'] + start_time, index=data.index)
print(data)
Missing is the conversion to datetime like Convert Pandas Column to DateTime
Upvotes: 0
Reputation: 109526
Something like this?
start_time = pd.Timestamp('2016-1-1 00:00')
df = pd.DataFrame({'seconds': [ 1, 2, 3]})
df['new_time'] = [start_time + dt.timedelta(seconds=s) for s in df.seconds]
>>> df
seconds new_time
0 1 2016-01-01 00:00:01
1 2 2016-01-01 00:00:02
2 3 2016-01-01 00:00:03
Upvotes: 1