Let's take a simple example. I have this first dataframe :
df = pd.DataFrame(dict(Name=['abc','def','ghi'],NoMatter=['X','X','X']))
df
Name NoMatter
0 abc X
1 def X
2 ghi X
For some reasons, I would like to use a for loop which add a column Value to df and do some treatments, from another dataframe changing at each iteration :
# strucutre of for loop I would like to use :
for i in range(something) :
add the column Value to df from df_value
other treatment not usefull here
# appearance of df_value (which change at each iteration of the for loop) :
Name Value
0 abc 1
1 def 2
2 ghi 3
However, I would prefer not to use merging, because that would require to delete the column Value added in the previous iteration before adding the one of the current iteration. Is there please a way to add the Value column to df by just an assignment starting like that :
df['Value'] = XXX
Expected output :
Name NoMatter Value
0 abc X 1
1 def X 2
2 ghi X 3
[EDIT]
I don't want to use merging because at the fourth iteration of the for loop, df would have the columns :
Name NoMatter Value1 Value2 Value3 Value4
Whereas I just want to have :
Name NoMatter Value4
I could delete the previous column each time but it seems not to be very efficient. This is why I'm just looking for a way to assign values to the Value column, not adding the column. Like an equivalent of the vlookup function in Excel applied to df from df_value data.