[英]Map Values from one dataframe to another based two criteria
I have one dataframe (df) that contains home field adavantage values for various conferences.我有一个数据框 (df),其中包含各种会议的主场优势值。 The first columns represents the home teams and the remaining column headers represent the away teams.
第一列代表主队,其余列标题代表客队。 I would like to create a new column, df1['hfa'] in the second dataframe (df1) that shows the home field advantage located in df for the respective matchups listed in df1.
我想在第二个数据框 (df1) 中创建一个新列 df1['hfa'],它显示了 df1 中列出的各个比赛的主场优势。 Below are images of the two dataframes.
下面是两个数据框的图像。 In excel I can achieve this with a two way lookup via Index Match.
在 excel 中,我可以通过索引匹配进行双向查找来实现这一点。 I would like to map the values from df to df1 for df1['hfa'] so that that they read: 2.5, 3.5, 4.5, etc. Thank you in advance!
我想将 df1['hfa'] 的值从 df 映射到 df1,以便它们读取:2.5、3.5、4.5 等。在此先感谢您!
I have the following code:我有以下代码:
df1['hfa'] = df1['Home Team'].map(df.set_index('Home Team')[])
I am unsure what to use in the final argument to match the Away Team from df1 to the same column header.我不确定在最后一个参数中使用什么来匹配来自 df1 的 Away Team 到相同的列标题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.