Is it possible to create more than one new column in Pandas when a dataframe is multiindexed? I would like to add a two new columns one and two under the bar2 supercolumn. Like so...
import pandas as pd
import numpy as np
arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo'],
['one', 'two', 'one', 'two', 'one', 'two']]
index = pd.MultiIndex.from_arrays(arrays, names=['first', 'second'])
df = pd.DataFrame(np.random.randn(3, 6), index=[1, 2, 3], columns=index)
df["bar2", ["one", "two"]] = np.random.randn(3, 2)
I know I can create them one by one using
df["bar2", "one"] = np.random.randn(3,1)
df["bar2", "two"] = np.random.randn(3,1)
Is there a quicker way of doing both at the same time?