Pd.merge "typeerror: String Indices Must Be Integers"
I have 3 files and my code is basically a series of merges that populates data from files 'lookup' and 'NonPO' into the file 'supplier' and create a new df called 'final2'. The cod
Solution 1:
You are trying to access NonPO
as your data frame, but in fact this is the variable that contains that filename, which is a string. Here it's clear
NonPO_Suppliers = pd.read_excel(NonPO)
Just change NonPO
to NonPO_Suppliers
and you should be fine.
final2 = pd.merge(final2, NonPO_Suppliers[['Unique','Category']], on='Unique', how='left')
Solution 2:
Consider this:
NonPO = r'//eu.ad.hertz.com/userdocs/irac920/Desktop/My Files/Python/Supplier cat testing/Non-PO Suppliers.xlsx'
NonPO_Suppliers = pd.read_excel(NonPO) # this is the name of the DataFrame, not NonPO.
Consequently, you need to change your code to this:
final2 = pd.merge(final2, NonPO[['Unique','Category']], on='Unique', how='left')
final2 = pd.merge(final2, NonPO_Suppliers[['Unique','Category']], on='Unique', how='left')
Hopefully this will work.
Post a Comment for "Pd.merge "typeerror: String Indices Must Be Integers""