简体   繁体   中英

find dataframe2 colum in dataframe1 column similar to the sql like operator and list the result from dataframe2 using pandas

import pandas as pd

xls1='C:\\Downloads\\Allparts.xlsx'

df = pd.read_excel(xls1,sheet_name='Data')

df=df['Part Number'].head(10)

xls2='C:\\Downloads\\Part_Details.xlsx'

dz = pd.read_excel(xls2,sheet_name='Data')

dz=dz.drop(dz.columns[[2, 4]], axis = 1)

dz=dz.drop(dz.columns[[3, 4, 5]], axis = 1)

for fd in df:

        if dz['Name'].str.contains(fd):
           print(dz['Name'],fd)

在此处输入图片说明

xls2: 在此处输入图片说明

Below code solved my purpose. Hope it helps others.

fdf=pd.dataframe()

for zd in dz['Name']:

 for fd in df['Part Number']:

           if str(zd) in str(fd):

               res=df[df['Part Number']==fd]
               fdf = pd.concat([fdf, res], axis=0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM