I'm trying to editing data with Pandas.
- I want to find letters in 'File1' by searching for letters in a column.
- I want to find the row that contains the letters while searching for the letters found in 'File 1' in 'File 2'.
is there a way I can do in this situation?
CodePudding user response:
You can do
df2['new'] = df2['col'].str.findall('|'.join(df1['col'].tolist()))
CodePudding user response:
Try this:
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))]