I have two data frames that I import from the excel sheets. There is some information I need to import from auxiliary dataframe to main dataframe if there is a matching. My code:
auxdf =pd.DataFrame({'prod':['look','duck','chik']},index=['prod_team1','prod_team2','prod_team3'])
auxdf =
prod
prod_team1 look
prod_team2 duck
prod_team3 chik
# Main dataframe after importing from an excel sheet
maindf =
col1 col2
mar_team1 aoo auxdf['prod_team1']
mar_team2 auxdf.loc['prod_team2'] bla
mar_team3 foo auxdf['prod_team3']
# I want to import information from auxdf into maindf
for i in range(len(mdf)):
for j in range(len(mdf.columns)):
# Check if a cell value has a string called 'auxdf', if so, change its value
try:
if 'auxdf' in maindf[maindf.columns[0]].iloc[0]:
maindf[maindf.columns[0]].iloc[0] = eval(maindf[maindf.columns[0]].iloc[0])
except:
pass
Expected output:
maindf =
col1 col2
mar_team1 aoo look
mar_team2 duck bla
mar_team3 foo chik
Need help to find most pythonic way of doing it. Thanks