Create New Dataframe Once Time-delta Is Higher Than Xy
I have a dataframe with the following scheme: Is it possible to create new dataframes according TimeDelta? So if TimeDelta is greater than e.g. 1.5, create new dataframe? So that
Solution 1:
You can use a custom group and split with groupby
.
First ensure that your "TimeDelta" values are numeric with pd.to_numeric
, then asses whether they are geater than 1.5, and apply a cumsum() to flag all the following rows up to the next value above threshold. Finally groupby
the custom group and convert to dict
.
group = pd.to_numeric(df.TimeDelta, errors='coerce').gt(1.5).cumsum()
my_dfs = dict(list(df.groupby(group)))
output:
>>> my_dfs
{0: time parameter TimeDelta
01800 -,
1: time parameter TimeDelta
137882245441,
2: time parameter TimeDelta
373443482441}
accessing a particular group:
>>> my_dfs[1] # secondgrouptimeparameter TimeDelta
137882245441
looping over the dataframes:
for group, dfin dict(list(df.groupby(group))).items():
print(f'group {group}')
print(df)
Post a Comment for "Create New Dataframe Once Time-delta Is Higher Than Xy"