我正在尋找一種優雅的解決方案來創建具有混合時間戳的多個資料幀
我有dataframe超過一千行的 16 列,其中一列具有時間戳值,例如:
2021-09-28 00:00:00 ~ 2021-09-28 23:59:59
此外,時間戳值不會在資料幀上繼續使用,而是混淆了時間戳。
例子
IN [1] : df["datetime"][24082:24085]
OUT [1] :
24082 2021-09-28 07:25:21.446
24083 2021-09-28 07:25:22.444
24084 2021-10-01 19:49:40.549
24085 2021-10-01 19:49:41.549
我想要做的是從資料幀創建多個資料幀取決于時間戳的日期,例如;
df1 is the rows with 2021-09-28 00:00:00.001 ~ 23:59:59.999
df2 is the rows with 2021-09-29 00:00:00.001 ~ 23:59:59.999
df3 is the rows with 2021-09-30 00:00:00.001 ~ 23:59:59.999
...
dfn is the rows with latest date
我怎樣才能達到abo4
我正在尋找優雅的解決方案輸出?
uj5u.com熱心網友回復:
使用groupby有Grouper:
for date, data in df.groupby(pd.Grouper(key='datetime', freq='D')):
# do_something_with_your_data
print(data)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/312990.html
