0

I have a pandas DataFrame like the following:

                  c  d
a  {'e': 1, 'f': 2}  2
b  {'e': 3, 'f': 4}  5

I would now like to expand the dictionaries in the cells to two sub-columns in a multiindex dataframe, like so:

     c          d
     e   f
a    1   2      2
b    3   4      5

How do I best do this?

user1376377
  • 125
  • 1
  • 1
  • 5
  • Fix column `'c'` using the duplicate, then use `.set_index()` – Trenton McKinney Jan 28 '21 at 21:08
  • Hi, thanks for the answer. I explicitly would like a multi-index dataframe. The answer that was referenced as duplicate isn't doing that for me... – user1376377 Jan 28 '21 at 21:18
  • You have asked two questions, however questions should address one issue. The first issue is to fix `'c'` using the duplicate. The second question is how to set a multiindex, which is done with `.set_index()`. – Trenton McKinney Jan 28 '21 at 21:25
  • If that doesn't work, [edit] the question to show what you have done, and specifically what is not working. Always provide a complete [mre] with code, **data, errors, current output, and expected output**, as **[formatted text](https://stackoverflow.com/help/formatting)**. Please see [How to ask a good question](https://stackoverflow.com/help/how-to-ask). – Trenton McKinney Jan 28 '21 at 21:28

0 Answers0