Having two dataframes where one of them has some value to be replaced in the other. What is the best way to replace the values?
For instance, the type:none in df1 should be replaced with the value in df2. This is the progress I have done so far, but I am not content with this approach:
df1=pd.DataFrame({"word":['The','big','cat','house'], "type": ['article','none','noun','none'],"pos":[1,2,3,4]})
df2=pd.DataFrame({"word":['big','house'], "type": ['adjective','noun'],"pos":[2,4]})
df1.set_index('pos',inplace=True, drop=True)
df2.set_index('pos',inplace=True, drop=True)
for i, row in df1.iterrows():
if row['type']=='none':
row['word']=df2.loc[df2.index[i],'word']
df1 dataframe should change to:
word type pos
0 The article 1
1 big adjective 2
2 cat noun 3
3 house noun 4
Thanks :)
.iterrows().