简体   繁体   English

将 dataframe 拆分为多个数据帧

[英]Split dataframe into multiple dataframes

I am learning pandas for a new project and I am relatively new and seeking help.我正在为一个新项目学习 pandas,我相对较新并寻求帮助。 I have the following dataframe.我有以下 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.从“ 2020-03-27 00:10:02 ”到2020-03-27 23:50:01的 DateTime 范围在 dataframe 中重复 18 次,在此时间轴内捕获不同类型的数据。

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 .我想将此 dataframe 拆分为不同的数据帧,每个数据帧都有自己的数据,这些数据与“ 2020-03-27 00:10:02 ”到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')] , 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.它在所有重复范围内选择几乎整个 dataframe。

Any suggestions?有什么建议么? Dataframe attached as an image. Dataframe 作为图像附加。 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.我想将“12:00:01 AM”到“11:50:01 PM”的每个范围分成一个 dataframe 。

Row1: 12:00:01 AM Row3588: 11:50:01 PM第 1 行:上午 12:00:01 第 3588 行:晚上 11:50:01

Row3589: 12:00:01 AM Row3876: 11:50:01 PM第 3589 行:上午 12:00:01 第 3876 行:晚上 11:50:01

Row3877: 12:00:01 AM Row4020: 11:50:01 PM第 3877 行:上午 12:00:01 第 4020 行:晚上 11:50:01

Row4021: 12:00:01 AM Row4452: 11:50:01 PM第 4021 行:上午 12:00:01 第 4452 行:晚上 11:50:01

I think you first need to make sure there is no duplicate and there are 18 different type of data for each DateTime index.我认为您首先需要确保没有重复,并且每个 DateTime 索引有 18 种不同类型的数据。

For example, it seems that there is only one row corresponding to 2020-03-27 23:50:01.例如,似乎只有一行对应于 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.此时,您还不能真正分离 dataframe,因为数据不是以一致的格式存储的。 If you can figure out ways to have 18 data types for each time, then you could try如果您能想出每次使用 18 种数据类型的方法,那么您可以尝试

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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