Reputation: 7490
I have a data frame like below:
i_id q_id
month category_bucket
Aug Algebra Tutoring 187 64
Balloon Artistry 459 401
Carpet Installation or Replacement 427 243
Dance Lessons 181 46
Landscaping 166 60
Others 9344 4987
Tennis Instruction 161 61
Tree and Shrub Service 383 269
Wedding Photography 161 49
Window Repair 140 80
Wiring 439 206
July Algebra Tutoring 555 222
Balloon Artistry 229 202
Carpet Installation or Replacement 140 106
Dance Lessons 354 115
Landscaping 511 243
Others 9019 4470
Tennis Instruction 613 324
Tree and Shrub Service 130 100
Wedding Photography 425 191
Window Repair 444 282
Wiring 154 98
It's a multi-index data frame with month and category bucket as index. And i_id, q_id as columns
I got this by doing a groupby operation on a normal data frame like below
invites_combined.groupby(['month', 'category_bucket'])[["i_id","q_id"]].count()
I basically want a data frame where I have 4 columns 2 each for i_id, q-Id for both the months and a column for category_bucket. So basically converting the above multi-index data frame to single index so that I can access the values.
Currently it's difficult for me to access the values of i_id, q_id along for a particular month and category value.
If you feel there is an easier way to access the i_id and q_id values for each category and month without having to convert to single index that is fine too.
Single index would be easier to loop into each value for each combination of month and category though.
Upvotes: 2
Views: 10543
Reputation: 862581
It seems you need reset_index
for convert MultiIndex
to columns
:
df = df.reset_index()
Upvotes: 5