So this recipe is a short example on how to unstack in python. Let's get started.
import pandas as pd import seaborn as sb
Let's pause and look at these imports. Pandas is generally used for performing mathematical operation and preferably over arrays. Seaborn is just for importing dataset for now.
df = sb.load_dataset('tips') print(df)
Here we have simply imported tips dataset from seaborn library and printed it.
df_stacked = df.stack() print(df_stacked)
Here, we are stacked our array and finally printing it.
Here, we are unstacking our array and finally printing it.
Once we run the above code snippet, we will see:
Scroll down the ipython file to visualize the final output.