I have this dataframe (with all 50 states and more categories, but if we can get this to work, I can apply it to the whole dataset):
US US_bp US_bp% AL AL_bp AL_bp%
total_pop 324173084 41393176 12.8 4920613 794326 16.1
white 198511109 19510415 9.8 3218517 378269 11.8
black 38526055 8402643 21.8 1260356 327284 26.0
And need this:
place total_pop bp bp% white_pop white_bp white_bp% black_pop black_bp black_bp%
0 US 324173084 41393176 12.8 198511109 19510415 9.8 8402643 840263 21.4
1 AL 4920613 794326 16.1 3218517 378269 11.8 1260356 327284 26.0
How can I do this with Pandas? I tried melt and pivot, but can't wrap my head around what might work.