Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

import numpy as np
import pandas as pd
from numpy.random import randn
from beakerx import beakerx, TableDisplay

beakerx.pandas_display_default()
df = pd.DataFrame(
    {"month": [1, 4, 7, 10], "year": [2012, 2014, 2013, 2014], "sale": [55, 40, 84, 31]}
)
df
Loading...

Add a Level to Row Index

df2 = pd.concat([df], keys=["Foo"], names=["Firstlevel"])
df2
Loading...
df2.index
MultiIndex(levels=[['Foo'], [0, 1, 2, 3]], labels=[[0, 0, 0, 0], [0, 1, 2, 3]], names=['Firstlevel', None])
df2.columns
Index(['month', 'year', 'sale'], dtype='object')

Add a Level to Column Index

df3 = pd.concat([df], keys=["Foo"], names=["Firstlevel"], axis=1)
df3
Loading...
df3.columns
MultiIndex(levels=[['Foo'], ['month', 'year', 'sale']], labels=[[0, 0, 0], [0, 1, 2]], names=['Firstlevel', None])
df3.index
RangeIndex(start=0, stop=4, step=1)