Skip to main content
deleted 2 characters in body
Source Link
Mayank Porwal
  • 34.2k
  • 9
  • 45
  • 65

To check if your df has Multiindex, you can do this:

isinstance(war_cinc.index, pd.MultiIndex)

This will return True.

To check for hierarchical columns, you can check nlevels:

if len(war_cinc.columns.nlevels) > 1:

This will be True in your case.

This will return True.

You can get the entire 2nd column like:

war_cinc[(   'cinc', 2)]

You need to pass all levels of the column in a tuple to fetch the column values.

To check if your df has Multiindex, you can do this:

isinstance(war_cinc.index, pd.MultiIndex)

To check for hierarchical columns, you can check nlevels:

if len(war_cinc.columns.nlevels) > 1:

This will be True in your case.

This will return True.

You can get the entire 2nd column like:

war_cinc[(   'cinc', 2)]

You need to pass all levels of the column in a tuple to fetch the column values.

To check if your df has Multiindex, you can do this:

isinstance(war_cinc.index, pd.MultiIndex)

This will return True.

To check for hierarchical columns, you can check nlevels:

if len(war_cinc.columns.nlevels) > 1:

This will be True in your case.

You can get the entire 2nd column like:

war_cinc[(   'cinc', 2)]

You need to pass all levels of the column in a tuple to fetch the column values.

added 147 characters in body
Source Link
Mayank Porwal
  • 34.2k
  • 9
  • 45
  • 65

To check if your df has MultiindexMultiindex, you can do this:

isinstance(war_cinc.index, pd.MultiIndex)

To check for hierarchical columns, you can check nlevels:

if len(war_cinc.columns.nlevels) > 1:

This will be True in your case.

This will return True.

You can get the entire 2nd column like:

war_cinc[(   'cinc', 2)]

You need to pass all indexeslevels of the column in a tuple to fetch the column values.

To check if your df has Multiindex, you can do this:

isinstance(war_cinc.index, pd.MultiIndex)

This will return True.

You can get the entire 2nd column like:

war_cinc[(   'cinc', 2)]

You need to pass all indexes of the column in a tuple to fetch the column values.

To check if your df has Multiindex, you can do this:

isinstance(war_cinc.index, pd.MultiIndex)

To check for hierarchical columns, you can check nlevels:

if len(war_cinc.columns.nlevels) > 1:

This will be True in your case.

This will return True.

You can get the entire 2nd column like:

war_cinc[(   'cinc', 2)]

You need to pass all levels of the column in a tuple to fetch the column values.

Source Link
Mayank Porwal
  • 34.2k
  • 9
  • 45
  • 65

To check if your df has Multiindex, you can do this:

isinstance(war_cinc.index, pd.MultiIndex)

This will return True.

You can get the entire 2nd column like:

war_cinc[(   'cinc', 2)]

You need to pass all indexes of the column in a tuple to fetch the column values.