Issue
I am new to Pandas. I have a dataframe and would like to split df -
The output should look like this -
df1 -
df2 -
Basically the dataframe must be split where my entire row values are 0. A for loop approach would be appreciated as my dataframe has many rows and many rows with 0 values Any help would be really appreciated.
Solution
You can check if all values in a row are 0, and use this to construct a custom group for splitting:
out = [g for _,g in df.groupby(df.eq(0).all(axis=1).cumsum())]
output (list of DataFrames):
[ Time Temperature
0 0 0
1 1 15
2 2 14,
Time Temperature
3 0 0
4 1 27]
intermediates:
Time Temperature .eq(0).all(axis=1) cumsum
0 0 0 True 1
1 1 15 False 1
2 2 14 False 1
3 0 0 True 2
4 1 27 False 2
Answered By - mozway
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.