Good Afternoon,
I want to do a vlookup between 2 dataframes so that they can be pivoted for a later task. The formula for this in excel is simple enough and is reliable.
=VLOOKUP(F2,$CU$2:$CV$2501,2,FALSE)
but when attempted with python this seems to cause an error somewhere and generates several hundred more records than should be expected.
What I am attempting to do is look at the marketing_event_id to see if it appears in the Details sheet and if it matches return the SrcCode in a new column.
rmNulls = pd.read_csv (r"File1.csv", converters={'marketing_event_id': lambda x: str(x)})
rmNulls['marketing_event_id'] = rmNulls['marketing_event_id'].replace('',0, inplace = True)
rmNulls["marketing_event_id"] = rmNulls["marketing_event_id"].astype(str)
details = pd.read_excel(r"DetailAttr.xlsx", "Details", dtype=str)
#Isolating the 2 required cols
refDetails = details[['SrcCode','New Minor Cat']].copy()
#Recasting code as str for merge
refDetails ["SrcCode"] = refDetails ["SrcCode"].astype(str)
print("Vlookup in Progress")
df3 = pd.merge(rmNulls,
refDetails ,
left_on= "marketing_event_id",
right_on ='SrcCode',
how ='left')
with pd.ExcelWriter('DW 150622.xlsx', date_format='DD-MM-YYYY', datetime_format='DD-MM-YYYY' ) as writer:
df3.to_excel(writer)
I use another column called date_value to filter the pivot table, with the pivot done in excel it ends up with 381, whereas pandas returns 475. I feel like this is related to the way my merge function is formatted but even after playing with it this still throws up a larger number than expected.
I have stepped through the code as I manipulate the df rmNulls and just before the merge I can in excel pivot it to give the correct numbers, so I do not believe that the date fields are to blame at this point.
Have I missed a trick with this or is there something just fundementally wrong with the way I'm attempting this.
Any help would be greatly appreciated.
Regards, Ryan