'How to create new dataframes from data frame which has Multi level columns?
I’ve this dataframe and want to create various other dataframes which consist of the Column State and other columns whose subtraction is to be done along with the subtraction result and the level 0 column name. Dataframe:
|State| Sheet1 | Sheet2 | Sheet3| | |count|c |d |count| c | d | |:————|:———:|—-|—:|:——-:|:—:|:————-:| |x | 100 |23|34|50 |4 | 56 | |:————|:———:|—-|—:|:——-:|:—:|:————-:| |y | 300 |13|34|60 |41 | 32 | |:————|:———:|—-|—:|:——-:|:—:|:————-:|
Desired dataframes are:
|State|Sheet1|Sheet2|Difference| | |count |count | | |:————|:——-—:|———-—:|:—————-—-:| |x | 100 |50 | 50 | |:————|:——-—:|———-—:|:—————-—-:| |y | 300 |60 |240 | |:————|:——-—:|————-:|:——————-—:|
And so on.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
