I have a large time-series dataframe at the second interval, and I need to preform some analysis on every grouping of 0-59 seconds. This is then used to be a feature in a different time-series dataframe by using the floor of the sub-section
I feel like I'm missing something basic, but unsure of the wording to get it right.
ex:
timestamp,close
2021-06-01 00:00:00,37282.0
2021-06-01 00:00:01,37282.0
2021-06-01 00:00:02,37285.0
2021-06-01 00:00:03,37283.0
2021-06-01 00:00:04,37281.0
2021-06-01 00:00:05,37278.0
2021-06-01 00:00:06,37275.0
2021-06-01 00:00:07,37263.0
2021-06-01 00:00:08,37264.0
2021-06-01 00:00:09,37259.0
...
2021-06-01 00:00:59,37260.0
2021-06-02 00:01:00,37261.0 --> new analysis starts here
2021-06-02 00:01:01,37262.0
# and repeat
My current implementation works, but I have a feeling is a really bad way of doing it.
df['last_update_hxro'] = df.apply(lambda x: 1 if x.timestamp.second == 59 else 0, axis=1)
df['hxro_close'] = df[df['last_update_hxro']==1].close
df['next_hxro_close'] = df['hxro_close'].shift(-60)
df['hxro_result'] = df[df['last_update_hxro']==1].apply(lambda x: 1 if x.next_hxro_close > x.hxro_close else 0, axis=1)
df['trade_number'] = df.last_update_hxro.cumsum() - df.last_update_hxro
unique_trades = df.trade_number.unique()
for x in unique_trades:
temp_df = btc_df[btc_df['trade_number']==x]
new_df = generate_sub_min_features(temp_df)
feature_df = feature_df.append(new_df)
def generate_sub_min_features(full_df):
# do stuff here and return a series of length 1, with the minute floor of the subsection as the key