How to get a proper formatted index in a pandas dataframe

Viewed 119

Having a dataframe like this:

>>> df = pd.DataFrame({'name': ['foo', 'foo', 'bar', 'bar'],
                   'colx': [1, 2, 3, 4],
                   'coly': [5, 6, 7, 8]})
>>> df.set_index('name', inplace=True)
>>> df
      colx  coly
name            
foo      1     5
foo      2     6
bar      3     7
bar      4     8

how is it possible to get a proper formatted index like:

      colx  coly
name            
foo      1     5
         2     6
bar      3     7
         4     8

so that pandas doesn't complains about duplicated indices.

1 Answers
Related