<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 stack = make stuff vertically stacked
unstack = spread stuff out horizontally
Step1:  missing data
Step2:  groupby + reshaping
<ASSISTANT_TASK:>
Python Code:
columns = pd.MultiIndex.from_tuples([
            ('A', 'cat', 'long'), ('B', 'cat', 'long'),
            ('A', 'dog', 'short'), ('B', 'dog', 'short')
        ],
        names=['exp', 'animal', 'hair_length']
    )
df = pd.DataFrame(np.random.randn(4, 4), columns=columns)
df
df.columns
stacked = df.stack(level=['exp','animal'])
stacked
stacked.reset_index(level=[0,1],drop=True).stack().to_frame().reset_index()
Explanation: stack = make stuff vertically stacked
unstack = spread stuff out horizontally
End of explanation
columns = pd.MultiIndex.from_tuples([('A', 'cat'), ('B', 'dog'),
                                         ('B', 'cat'), ('A', 'dog')],
                                        names=['exp', 'animal'])
index = pd.MultiIndex.from_product([('bar', 'baz', 'foo', 'qux'),
                                        ('one', 'two')],
                                       names=['first', 'second'])
df = pd.DataFrame(np.random.randn(8, 4), index=index, columns=columns)
df
df3 = df.iloc[[0, 1, 4, 7], [1, 2]]
df3
df
Explanation: missing data
End of explanation
df.stack()
df.stack().mean(1).unstack()
Explanation: groupby + reshaping
End of explanation
<END_TASK>