Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

328
Views
Dictionary of Pandas Dataframes to MultiIndex Dataframe

I have a dict of Pandas Dataframes, say

d = {A: pd.DataFrame([[0, 1, 2], [2, 2, 4]),
     B: pd.DataFrame([[1, 1, 1], [2, 2, 2]}

and I'd like to change it into a MultiIndex DataFrame like this:

A 0   0, 1, 2
  1   2, 2, 4
B 0   1, 1, 1
  1   2, 2, 2
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Use pd.concat on the dictionary values, with the keys parameter set to the dictionary keys:

df = pd.concat(d.values(), keys=d.keys())

The resulting output:

     0  1  2
A 0  0  1  2
  1  2  2  4
B 0  1  1  1
  1  2  2  2
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!