I have two dfs and trying to create a new colum df1['Conv_Amount'] by dividing df1['Amount'] by df2['Conv_Value'] if df1['Curr_Code'] matches df2['Curr_Code'].
Code:
##some other code
df1 = old_df[req_cols]
cnt = len(df1.index)
df1['Conv_Amount'] = df1.merge(df2).assign(soln=lambda df: df.Amount/ df.Conv_Value).soln
tot_amt = df1['Conv_Amount'].sum()
After merge/divide df1['Conv_Amount'] is not having the values im expecting and im seeing this warning:
SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
df1['Conv_Amount'] = df1.merge(df2).assign(soln=lambda df: df.Amount/ df.Conv_Value).soln
The same code was working well before but not now. I have tried many solutions from SO but no luck. Im a newbie to pandas and trying to understand these indexing concepts. Any help is really appreciated. Thanks!