Split Pandas DataFrame with DatetimeIndex by na or missing rows into blocks

ch3f

I hava a Pandas DataFrame with a DatetimeIndex and want to split it into blocks of continously connected rows removing the nan rows.

                           Temperature  Humidity
2020-01-01 00:00:00+00:00  20           40 
2020-01-01 00:01:00+00:00  21           40
2020-01-01 00:02:00+00:00  NaN          NaN
2020-01-01 00:03:00+00:00  22           41
2020-01-01 00:04:00+00:00  NaN          NaN
2020-01-01 00:05:00+00:00  NaN          NaN
2020-01-01 00:06:00+00:00  NaN          NaN
2020-01-01 00:07:00+00:00  21           41
2020-01-01 00:08:00+00:00  21           41
2020-01-01 00:09:00+00:00  21           42

Result should be a list of the following three DataFrames:

                           Temperature  Humidity
2020-01-01 00:00:00+00:00  20           40 
2020-01-01 00:01:00+00:00  21           40

                           Temperature  Humidity
2020-01-01 00:03:00+00:00  22           41

                           Temperature  Humidity
2020-01-01 00:07:00+00:00  21           41
2020-01-01 00:08:00+00:00  21           41
2020-01-01 00:09:00+00:00  21           42

Any help?

BEN_YO

Let us try use cumsum with isnull create the groupby key

d = {x : y for x , y in df.dropna().groupby(df.isnull().cumsum().sum(1))}
d[0]
                          Temperature  Humidity
2020-01-0100:00:00+00:00         20.0      40.0
2020-01-0100:01:00+00:00         21.0      40.0

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Python Pandas: Split DateTimeIndex in two at missing timestamp

From Dev

Selecting rows with specified days in datetimeindex dataframe - Pandas

From Dev

Optimize: split pandas DataFrame with DatetimeIndex based on date into list

From Dev

How to split dataframe or reorder dataframe by rows in pandas

From Dev

How to fill the missing rows of Pandas DataFrame with zeros?

From Dev

Find missing data in pandas dataframe and fill with NA

From Dev

pandas DataFrame split the column and extend the rows

From Dev

Split cell into multiple rows in pandas dataframe

From Dev

PANDAS split dataframe to multiple by unique values rows

From Dev

Split list in rows python pandas dataframe

From Dev

Pad rows with no data as Na in Pandas Dataframe

From Dev

Modify hour in datetimeindex in pandas dataframe

From Dev

Shifting values in datetimeindex of pandas dataframe

From Dev

Split DatetimeIndex into date and time MultiIndex conveniently in Pandas

From Dev

Pandas.Dataframe.duplicated() includes missing rows as duplicates

From Dev

Reshape Pandas Dataframe with duplicate Index and fill missing rows

From Dev

Split pandas dataframe in two if it has more than 10 rows

From Dev

Split a Pandas Dataframe into multiple smaller dataframes based on empty rows

From Dev

How to loop through Pandas DataFrame and split a string into multiple rows

From Dev

Split pandas dataframe into multiple dataframes with equal numbers of rows

From Dev

Pandas: Split a dataframe rows and re-arrange column values

From Dev

DataFrame Split On Rows and apply on header one column using Python Pandas

From Dev

fill missing rows in a dataframe

From Dev

Slice DataFrame using pandas Timestamp on DatetimeIndex

From Dev

Load price ticker into Pandas dataframe with DatetimeIndex

From Dev

Pandas Resample Missing Rows

From Dev

split item to rows pandas

From Dev

split item to rows pandas

From Dev

Split columns into rows in Pandas

Related Related

  1. 1

    Python Pandas: Split DateTimeIndex in two at missing timestamp

  2. 2

    Selecting rows with specified days in datetimeindex dataframe - Pandas

  3. 3

    Optimize: split pandas DataFrame with DatetimeIndex based on date into list

  4. 4

    How to split dataframe or reorder dataframe by rows in pandas

  5. 5

    How to fill the missing rows of Pandas DataFrame with zeros?

  6. 6

    Find missing data in pandas dataframe and fill with NA

  7. 7

    pandas DataFrame split the column and extend the rows

  8. 8

    Split cell into multiple rows in pandas dataframe

  9. 9

    PANDAS split dataframe to multiple by unique values rows

  10. 10

    Split list in rows python pandas dataframe

  11. 11

    Pad rows with no data as Na in Pandas Dataframe

  12. 12

    Modify hour in datetimeindex in pandas dataframe

  13. 13

    Shifting values in datetimeindex of pandas dataframe

  14. 14

    Split DatetimeIndex into date and time MultiIndex conveniently in Pandas

  15. 15

    Pandas.Dataframe.duplicated() includes missing rows as duplicates

  16. 16

    Reshape Pandas Dataframe with duplicate Index and fill missing rows

  17. 17

    Split pandas dataframe in two if it has more than 10 rows

  18. 18

    Split a Pandas Dataframe into multiple smaller dataframes based on empty rows

  19. 19

    How to loop through Pandas DataFrame and split a string into multiple rows

  20. 20

    Split pandas dataframe into multiple dataframes with equal numbers of rows

  21. 21

    Pandas: Split a dataframe rows and re-arrange column values

  22. 22

    DataFrame Split On Rows and apply on header one column using Python Pandas

  23. 23

    fill missing rows in a dataframe

  24. 24

    Slice DataFrame using pandas Timestamp on DatetimeIndex

  25. 25

    Load price ticker into Pandas dataframe with DatetimeIndex

  26. 26

    Pandas Resample Missing Rows

  27. 27

    split item to rows pandas

  28. 28

    split item to rows pandas

  29. 29

    Split columns into rows in Pandas

HotTag

Archive