0

I have a dataframe which looks like this:

   Repo Averages for 25 Apr 2018    

Business Date   Instrument
25/04/2018  GC_AUSTRIA_SUB_10YR
25/04/2018  GC_AUSTRIA_SUB_10YR
25/04/2018  R_RAGB_1.15_10/18
25/04/2018  R_RAGB_4.35_03/19
25/04/2018  R_RAGB_4.35_03/19
25/04/2018  R_RAGB_1.95_06/19

I am looking to drop levels and get a dataframe similar to

  Business Date Instrument
    25/04/2018  GC_AUSTRIA_SUB_10YR
    25/04/2018  GC_AUSTRIA_SUB_10YR
    25/04/2018  R_RAGB_1.15_10/18
    25/04/2018  R_RAGB_4.35_03/19
    25/04/2018  R_RAGB_4.35_03/19
    25/04/2018  R_RAGB_1.95_06/19

I have asked this question before and I know that I should be using df.columns.droplevel(1) but this time it does not work I get an error

AttributeError: 'Index' object has no attribute 'droplevel'

it is very strange that I get this message because in the same script i use similar trick to drop level. Yet for this dataframe it does not work. I am a bit puzzled,

In python the output looks like this

Out[226]:

    Repo Averages for 25 Apr 2018           Unnamed: 1
1                   Business Date           Instrument
2                      25/04/2018  GC_AUSTRIA_SUB_10YR
3                      25/04/2018  GC_AUSTRIA_SUB_10YR
4                      25/04/2018    R_RAGB_1.15_10/18
5                      25/04/2018    R_RAGB_4.35_03/19
6                      25/04/2018    R_RAGB_4.35_03/19
7                      25/04/2018    R_RAGB_1.95_06/19

Help is appreciated

3
  • Can you out put df .columns here Commented May 14, 2018 at 16:35
  • @Wen modified my question to add additional info on the output Commented May 14, 2018 at 16:39
  • This is not multiple index , see my answer : -) Commented May 14, 2018 at 16:40

1 Answer 1

1

That is not multiple index , try following

df.columns=df.iloc[0,:]
df=df.iloc[1:,:]
df
Sign up to request clarification or add additional context in comments.

1 Comment

the answer you suggested does not lead to a dataframe where I can select 'Business Date' and 'Instrument'.

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.