df
religion | <$10k | $10-20k | $20-30k | $30-40k | $40-50k | $50-75k | |
---|---|---|---|---|---|---|---|
0 | Agnostic | 27 | 34 | 60 | 81 | 76 | 137 |
1 | Atheist | 12 | 27 | 37 | 52 | 35 | 70 |
2 | Buddhist | 27 | 21 | 30 | 34 | 33 | 58 |
3 | Catholic | 418 | 617 | 732 | 670 | 638 | 1116 |
4 | Dont know/refused | 15 | 14 | 15 | 11 | 10 | 35 |
5 | Evangelical Prot | 575 | 869 | 1064 | 982 | 881 | 1486 |
6 | Hindu | 1 | 9 | 7 | 9 | 11 | 34 |
7 | Historically Black Prot | 228 | 244 | 236 | 238 | 197 | 223 |
8 | Jehovahs Witness | 20 | 27 | 24 | 24 | 21 | 30 |
9 | Jewish | 19 | 19 | 25 | 25 | 30 | 95 |
df_melt = df.melt(id_vars="religion", var_name='income', value_name='freq')
df_melt.sort_values(by=["religion"], inplace=True)
df_melt
religion | income | freq | |
---|---|---|---|
0 | Agnostic | <$10k | 27 |
30 | Agnostic | $30-40k | 81 |
40 | Agnostic | $40-50k | 76 |
50 | Agnostic | $50-75k | 137 |
10 | Agnostic | $10-20k | 34 |
... | ... | ... | ... |
39 | Jewish | $30-40k | 25 |
19 | Jewish | $10-20k | 19 |
9 | Jewish | <$10k | 19 |
49 | Jewish | $40-50k | 30 |
59 | Jewish | $50-75k | 95 |
60 rows × 3 columns