Reputation: 12207
I have a list of dataframes, each has a multi-index. one column is a varName, the other is 'round'.
The values in the varName column are numbers. I have another dataframe that is a mapping of the numbers to labels. I want to use map() on the varName column, but since it's part of the index, there IS no varName column.
I've tried to copy the varname column, or make it not part of the index anymore, but none of these things seem to work.
Upvotes: 1
Views: 641
Reputation: 3751
maybe you can do something like:
df.reset_index(level=1).merge(df2)
this is assuming level=1 is your common column (eg 'varName') between two dfs. if you wish you can than set_index for the label name, like:
df.reset_index(level=1).merge(df2).set_index(['labels'],append=True)
Upvotes: 0
Reputation: 42905
If varName
is the name
of one of the MultiIndex
levels, you should be able to:
df.reset_index(level='varName')
to convert varName
to a column
and then use map()
. If varName
is not the name
, you should still be able to use level=0
(or 1
).
Upvotes: 1