简体   繁体   中英

Split dataframe into multiple dataframes

I am learning pandas for a new project and I am relatively new and seeking help. I have the following dataframe.

The DateTime range from “ 2020-03-27 00:10:02 ” to 2020-03-27 23:50:01 repeats 18 times across the dataframe capturing different types of data within this timeline.

I would like to split this dataframe into different dataframes each one having its own data related to the range “ 2020-03-27 00:10:02 ” to 2020-03-27 23:50:01 .

When I try:

df [(df["Date"] > '2020-03-27 00:10:00') & (df ["Date"] < '2020-03-27 23:55:00')] ,

it selects the almost the entire dataframe across all the repetitive ranges.

Any suggestions? Dataframe attached as an image. enter image description here

Adding further information that the range repeats like below. (Although the length of the range is not important).

I would like to segregate each range of "12:00:01 AM" to "11:50:01 PM" into a dataframe each.

Row1: 12:00:01 AM Row3588: 11:50:01 PM

Row3589: 12:00:01 AM Row3876: 11:50:01 PM

Row3877: 12:00:01 AM Row4020: 11:50:01 PM

Row4021: 12:00:01 AM Row4452: 11:50:01 PM

I think you first need to make sure there is no duplicate and there are 18 different type of data for each DateTime index.

For example, it seems that there is only one row corresponding to 2020-03-27 23:50:01. At this point, you cannot really separate the dataframe yet since the data is not stored in a consistent format. If you can figure out ways to have 18 data types for each time, then you could try

df_type1 = df.loc[[i for i in range(9820) if i % 18 ==0],:]
df_type2 = ...

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