2

I have a data-frame df1 that looks like:

                 col2  col3
date       dept            
2020-05-07 A       29    21
2020-05-08 B       56    12
2020-05-09 C       82    15
2020-05-10 D       13     9
2020-05-11 E       35    13
2020-05-12 F       53    87
2020-05-13 G       25     9
2020-05-14 H       23    63

the data-frame has two index columns (date and dept). How can I change the data-frame so that it is only indexed by date? So my desired output looks like:

           dept  col2  col3
date                   
2020-05-07    A    29    21
2020-05-08    B    56    12
2020-05-09    C    82    15
2020-05-10    D    13     9
2020-05-11    E    35    13
2020-05-12    F    53    87
2020-05-13    G    25     9
2020-05-14    H    23    63

I have tried to use:

df1 = df1.reset_index('date')

without success.

0

1 Answer 1

1

Here is necessary select column(s) or position(s) for converting to columns:

#convert dept to columns
df1 = df1.reset_index(level='dept')
#convert date to columns
#df1 = df1.reset_index('date')

Or:

df1 = df1.reset_index(level=1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.