I have a Pandas DataFrame with a column index like the one below:
+----+----+----+----+----+----+
| A1| A2| A3| B1| B2| B3|
+----+----+----+----+----+----+
...the data
What I would like to do is to change the column index of this DataFrame to a multi-index one, as shown in the format below, without modifying the data and just simply adding an upper level in the index (with values A and B).
+--------------+--------------+
| A | B |
+----+----+----+----+----+----+
| A1| A2| A3| B1| B2| B3|
+----+----+----+----+----+----+
...the data
I have tried to use the pandas.MultiIndex function but with no luck. How can this be solved?
pd.MultiIndex.from_arraysis necessary? Notdf.columns = [df.columns.str[0], df.columns]?