I have the following data in a pandas data frame. The data is sampled at 50khz hence the 'microsec' filed has to incremented for each ID group by 50.
Data ----ID ---- microsec
0.304 ----1 ---- 1530348553000
0.276 ----1 ----15303485530000
0.276 ----1 ----15303485530000
0.276 ----2 ----15303490090000
0.276 ----2 ----15303490090000
0.304 ----2 ----15303490090000
0.276 ----3 ----15303553530000
1.359 ----3 ----15303753680000
1.443 ----3 ----15303753680000
Output Required
Data ----ID ---- microsec
0.304 ----1 ---- 1530348553000
0.276 ----1 ----15303485530050
0.276 ----1 ----15303485530100
0.276 ----2 ----15303490090000
0.276 ----2 ----15303490090050
0.304 ----2 ----15303490090100
0.276 ----3 ----15303553530000
1.359 ----3 ----15303753680050
1.443 ----3 ----15303753680100
CODE
import numpy as np
from itertools import chain
lens = list(map(len, df['Data'].str.split('|')))
df['microsec'] = pd.DatetimeIndex ( df['DateTime'] ).astype ( np.int64 )// 10 ** 9
df['Data'] = df['Data'].str.replace(',','.')
res = pd.DataFrame({'ID': np.repeat(df['ID'], lens),
'microsec': np.repeat(df['microsec']*10000, lens),
'Data': list(chain.from_iterable(df['Data'].str.split('|')))
})
res[['Data']] = res[['Data']].astype(float)
res.to_csv('samplefile.txt', index=False)
What I tried
df_groups = res.groupby('MeasurementID')
for MeasurementID,microsec in df_groups:
microsec = microsec*50
print(microsec)
But I did not achieve my desired output. Please let me know where I am doing wrong.