I have some data like follow structure. It used in python pandas Data Frame and I named it df.
Data1,Data2,Flag
2016-04-29,00:40:15,1
2016-04-29,00:40:24,2
2
I built a generator to produce the rows then used pd.concat
def get_row(df):
ref = None
for i, row in df.iterrows():
if ref is not None:
cond1 = (row.Data2.total_seconds() -
ref.Data2.total_seconds() > 18)
cond2 = row.Flag != ref.Flag
if ref is None or cond1 or cond2:
yield row
ref = row
pd.concat([r for r in get_row(df)], axis=1).T
Because @Kartik insisted :-)