我试图在python中连接以下数据集:
df1:
class, cvss, cwe, description, line, reccomandation, vul_id
a.class cvss1 cwe1, desc1, l1, rec1, vul1df2:
Title,NTimes,Synopsis,Description,Solution,Risk Factor,CVSS Temporal Score
tit1, nt1 syn1 desc2 sol1 risk1 cvss2
tit2, nt2 syn2 desc3 sol2 risk2 cvss3我希望将df1.cwe、df1.description、df1.cvss列的信息添加到df2.Title、df2.Description和df2.CVSS时间分数中,以获得以下情况:
class, line,reccomandation,vul_id,Title,NTimes,Synopsis,Description,Solution,Risk Factor,CVSS Temporal Score
a.class l1 rec1 vul1 cwe1, desc1 cvss1
tit1 nt1 syn1 desc2 sol1 risk1 cvss2
tit2 nt2 syn2 desc3 sol2 risk2 cvss3我尝试过使用merge,但没有成功地使用以下代码:
res= pd.merge(df1,df2 left_on=['cwe','description','cvss'],right_on=['Title','Description','CVSS Temporal Score']) 发布于 2022-01-05 19:29:59
只需使用以下方法:
#create new empty data frame
df = pd.DataFrame()
#add the columns from df1 to df
df['cwe']=df1['cwe']
#add the rest of the columns from df1 to df as above
#add the columns from df2 to df
df['title']=df1['title']
#add the rest of the columns from df2 to df as above
#view the new dataframe
dfhttps://stackoverflow.com/questions/70598034
复制相似问题