I am importing excel files with products and product specific data. They look like this:
dfA
EAN Code Product Name Color Price
12345 AAA xxx 9
45678 BBB zzz 10
and dfB
EAN Code Product Name New Price
12-345 AAA 10
45-678 BBB 11
I am importing these as always:
dfA = pd.DataFrame (dfA, columns=["Season", "EAN Code", "Product Name", "..."] , dtype=str)
And I am merging them, since there are multiple different excel files:
dfA = pd.concat([dfA1, dfA2, dfA3, dfA4, dfA5, dfA6, dfA7, dfA8, dfA9, dfA10, dfA11], ignore_index=False)
Then I am deleting the hyphen in the EAN column, because in excel file b there is an unnecessary hyphen in the EAN number.
for col in dfB.columns:
dfB["EAN"] = dfB["EAN"].str.replace('-', '')
So far, so good.
Now I try to search through the EAN code column of dfA and search for the same product in dfB. When there is a match, I want to copy over the new price. This worked great in my old code, although it took about 15 minutes for the script to search through a half million rows... This worked quite well in the past, but now I am trying to achieve the same, but I get an error message. This is my simplified code:
for i in dfA.index:
for j in dfB.index:
if dfA.loc[i, "EAN"] == dfB.loc[j, "EAN"]:
print ("EAN", number,"times found!")
number=number+1
dfA.loc[i, "Price"] = dfB.loc[j, "New Price"]
The print statement is only a feedback for me, so that I see wether the script is still doing something.
Traceback (most recent call last):
File "c:...", line 72, in <module>
if dfA.loc[i, "EAN"] == dfB.loc[j, "EAN"]:
File "C:...", line 1527, in __nonzero__
raise ValueError(
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Why am I getting this now?