![](/img/trans.png)
[英]Python how to join/merge Pandas dataframes with matching columns of specific values from different dataframes
[英]How to find matching values in 3 columns of 2 different dataframes in pandas and perform an action when the condition is true
我没有测试它,因为我没有您提供的示例数据集,但是这是我使用pd.merge的解决方案:
pd.merge(df1, df2[['Application_ID', 'Task Type', 'Task Category', 'Task_ID']],
on=['Application_ID', 'Task Type', 'Task Category'], how='left')
希望它有效!
尝试这样的事情:
df1 = pd.DataFrame({
'Overal PIA Status': ['In Progress'],
'Task Type': ['Privacy Monitoring'],
'Task Category': ['PIA Monitoring'],
'Due Date': ['9/30/2022'],
'Custodian': ['asdfghjkl'],
'Application_ID': [1234]
})
df2 = pd.DataFrame({
'Task Type': ['Privacy Monitoring'],
'Task Category': ['PIA Monitoring'],
'Task Title': ['Application PIA Not Started'],
'Due Date': ['9/24/2022'],
'Task Owner': ['asdfghjkl'],
'Application_ID': [1234],
'Task_ID': [5678]
})
df1['Task_ID'] = [
df2['Task_ID'][i]
if set(df2[['Application_ID', 'Task Type', 'Task Category']].iloc[i])
== set(df2[['Application_ID', 'Task Type', 'Task Category']].iloc[i])
else None
for i in range(len(df1))
]
print(df1)
Output:
Overal PIA Status Task Type Task Category Due Date Custodian Application_ID Task_ID
0 In Progress Privacy Monitoring PIA Monitoring 9/30/2022 asdfghjkl 1234 5678
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.