简体   繁体   中英

Filter data based on timestamp in pandas

My input dataset is below.

输入

What is the best way to create multiple new datasets with time stamp of 09:15:00, 10:15:00 so on..

Output dataset to be

输出数据集

I can't tell if your datetime column is an index or a column without a name? If its a column without a name:

df = df.rename(columns={"": "DateTime"})
df["Time"] = pd.to_datetime(df["DateTime"]).dt.time

df_dict = {x: pd.DataFrame for x in df["Time"].unique()}
for key in df_dict.keys():
    df_dict[key] = df.query("Time.eq(@key)").reset_index(drop=True)

    print(f"{df_dict[key]}\n")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM