Split pandas dataframe rows up to searched column value into new dataframes

One can use eq to check for the header rows, then groupby on the cumsum:

header_rows = df.eq(df.columns).all(1)
dfs = {k:v for k,v in df[~header_rows].groupby(header_rows.cumsum())}

then, for example dfs[0] gives:

   A  B
0  1  9
1  2  8
2  3  7

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top