Created
November 28, 2019 17:03
-
-
Save aksinghdce/b6dfdbd6eba4c3098e4979136a4e7440 to your computer and use it in GitHub Desktop.
Create Pandas DataFrame with multi-level columns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
columns = [("term", "word"), ("term", "phrase"), ("context", "academic"), ("context", "non-academic"), ("meaning", "short"), ("meaning", "long")] | |
df = pd.DataFrame(columns=columns) | |
df.columns = pd.MultiIndex.from_tuples(columns) | |
# To set values | |
df.loc[0, ("term", "word")] = "condescension" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment