0

I have the dataframe that you can see in figure A. I want it to be like figure B, so that I can plot bars. So, how can I eliminate all the indexes?

Here is my code:

    df2.reset_index('level_1',drop=True)
    df2.plot(kind='bar', subplots=True, figsize=(13,15), legend=False)

Figure A

Figure A

Figure B enter image description here

Aizzaac
  • 3,146
  • 8
  • 29
  • 61
  • Hard to diagnose (for me) .. what is the output if you do`df2.columns.name` and `df2.index.name`? – Alex Dec 09 '16 at 00:16
  • Please don't post your data as images... Read [mcve](http://stackoverflow.com/help/mcve) and [how to create good reproducible pandas examples](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – Julien Marrec Dec 09 '16 at 00:58
  • okey. I will be more careful when posting images. – Aizzaac Dec 09 '16 at 14:44

1 Answers1

1

You don't have a hierarchical index for either your index or your columns. What you are seeing is the names of the index and the columns. level_0 is the name for the columns and level_1 is the name for the index. They should not affect any code. If you want to eliminate them you can do del df.index.name and del df.columns.name or set them equal to an empty string.

See this sample dataframe with no names for index or columns

df = pd.DataFrame({'a':[1,2,3], 'b':[2,4,5]})

enter image description here

Now, lets add names to both the index and columns

df.columns.name = 'level_0'
df.index.name = 'level_1'

enter image description here

And get rid of them again

del df.columns.name, df.index.name
Ted Petrou
  • 59,042
  • 19
  • 131
  • 136
  • You are right! It was not necessary to remove the names of index and columns. The reason I could not plot was because I forgot to put: %matplotlib inline – Aizzaac Dec 09 '16 at 14:56