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?
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.
Comments