I have two dataframes as shown below, and I'm trying to set value to CLASSIFICATION in dataframe1 based on dataframe2's ITEM/CODE. If DESC has any matching word to ITEM/CODE then I have to get TYPE from dataframe2.
To achieve this, I am splitting the DESC string, and trying to compare the list entries with ITEM/CODE of dataframe2. Any Ideas on how to do this?
dataframe1
PN DESC CLASSIFICATION
C23890 Resistor 2.21K elec
C23891 Powerswitch
C23892 Resistor 7.5K
C23893 Resistor .1K
C23894 FET elec
C23895 ELE SD Card adapter
C23896 Crystal 16Mhz
C23897 Capacitor 100uF
C23898 ELECTRONICS Resistor 10K
C23899 M3x5 Socket Cap Bolt MECH
C23900 M3x6 Socket Cap Bolt Mech
C23901 Mehcanical Assemble Kapton Tape 120mm
C23902 MK7 Filament Drive Block Front
C23903 Pulley 5mm shaft
dataframe2
ITEM/CODE TYPE
ELE ELECTRONIC
ELECTRONICS ELECTRONIC
Capacitor ELECTRONIC
Resistor ELECTRONIC
Washer MECHANICAL
MECH MECHANICAL
This is what I have coded up so far.
import pandas as pd
fn = 'D:\PartsExport.xlsx'
dfInput = pd.read_excel(fn, 'Sheet1')
fn_type = 'D:\TypeMaster.xlsx'
dfType = pd.read_excel(fn_type, 'Sheet1')
dfInput['DESC_SPLIT'] = dfInput["DESC"].str.split(" ", n=-1, expand = False)
Result
PN DESC CLASSIFICATION
C23890 Resistor 2.21K elec ELECTRONIC
C23891 Powerswitch ELECTRONIC
C23892 Resistor 7.5K ELECTRONIC
C23893 Resistor .1K ELECTRONIC
C23899 M3x5 Socket Cap Bolt MECH MECHANICAL