【发布时间】:2021-12-20 23:21:33
【问题描述】:
【问题讨论】:
-
文件1和文件2是dataframe格式吗?
-
如果您在问题的文本中包含文件 1 和文件 2,您将获得更好的帮助
-
是的!它们都是数据帧格式。
标签: python pandas string dataframe contains
【问题讨论】:
标签: python pandas string dataframe contains
试试这个:
df1 = pd.DataFrame({'file1' : ['JVD', 'WFX', 'DGC', 'HHD', 'WEV', 'IUV',
'MDE']})
df2 = pd.DataFrame({'file2' : ['123JVD42', '123WFX3', '234WEV', '231sD2']})
searchfor = list(df1['file1'])
df2[df2['file2'].str.contains('|'.join(searchfor))]
【讨论】:
你可以的
df2['new'] = df2['col'].str.findall('|'.join(df1['col'].tolist()))
【讨论】: