I have data like:
df1 = pd.DataFrame(columns=list('XY'))
df1['X'] = np.arange(0,100,0.1)
df1['Y'] = np.cos(df1['X']) + 30
df2 = pd.DataFrame(columns=list('AB'))
symbols['X'] = [22, 43, 64, 86]
And I am defining a function as:
def find_nearest(df1, df1['X'], df2['A'], df1['Y']):
array = np.asarray(df1['X'])
idx = (np.abs(array - df2['A'])).argmin()
return df1.iloc[idx][df1['Y']]
But I get a syntax error when calling on the columns of the dataframes in the line:
def find_nearest(df1, df1['X'], df2['A'], df1['Y']):
It seems like the function doesn't like when I directly call on columns of dataframes. If I assign the columns into their own variables, this works fine. But for memory sake, I am trying to avoid that.
Does anyone know a workaround? If anything needs clarification, let me know.