I am writing an automation script for work and the key feature of it is hanging me up. I need to fill in one spreadsheet based on information from another spreadsheet. I've created a simplified scenario that replicates my problem.
One sheet, my reference sheet, has the lookup information spread among several columns:
https://www.dropbox.com/s/wby8yyljkyz1o74/lookup_ref.csv?dl=0
The fill-in sheet needs to have the relevant number filled in based on another matching value:
https://www.dropbox.com/s/h9knreacqamjvbg/fill_in_d_number.csv?dl=0
Here's my code:
import pandas as pd
df_ref = pd.read_csv('lookup_ref.csv')
df_fillin = pd.read_csv('fill_in_d_number.csv')
def get_d_number(food):
return df_ref[df_ref.eq(food).any(1)].d_number.item()
df_fillin.insert(0, 'd_number', get_d_number(df_fillin['food']))
and I'm getting this:
ValueError: can only convert an array of size 1 to a Python scalar
Can anyone help with this? It seems like something that should be really simple, and if it worked it would save me a LOT of work.