Home > Blockchain >  How to transform simple index dataframe to multi-index dataframe
How to transform simple index dataframe to multi-index dataframe

Time:05-24

considering this DataFrame, I don't know how to have a multi index DataFrame using Pandas :

Before oder index

To fix it you can sort the incidence with sort_index.

df.sort_index(ascending=False, inplace=True)

After order index

The final result of the code would be.

df.set_index(['industry', df.index], inplace=True)
df.sort_index(ascending=False, inplace=True)

NOTE: The values used in the dataframe are from examples and do not necessarily coincide with those of your photograph.

CodePudding user response:

Try

df = df.set_index(["industry", "URL article"])
  • Related