0

I have data stored in a SQL database. When I call this data, it gets back to me as a DataFrame (I am using pandas).

I then set_index to organized it as a MultiIndex level DataFrame.

data.set_index(['colname1', 'colname2', 'colname3'],inplace=True)

However, my Data isn't shaped in a fully organized way. Meaning I would like this data to be stored this way:

How I would like it to be:

enter image description here

And currently it's returned this way, in a non organized way:

enter image description here

DavidG
  • 24,279
  • 14
  • 89
  • 82
ruh
  • 139
  • 3
  • 9
  • did you try `df = df.sort_index()`? – cs95 Dec 13 '17 at 11:05
  • Works perfectly! Sometimes it easier than we thought. Thanks – ruh Dec 13 '17 at 11:06
  • Okay, great. Just wanted to confirm, since this appears to be a duplicate. – cs95 Dec 13 '17 at 11:08
  • Indeed, I am new in pandas, sometimes I don't know exactly how to check for existing subjects. But thanks for the warning. Will spend more time looking next time. – ruh Dec 13 '17 at 11:17

0 Answers0