Oct-07-2019, 07:15 AM
Hi there,
I'm a newbie in Python and I need your help.
I tried to search my answer in the forum but I think I don't have the good keywords... It's a shame because the issue seems to be simple (but I'm even not sure of this !). Here's the problem :
I work with 2 dataframes df1 and df2.
df1 has n rows and 3 columns (A has only "NaN") :
ColA |ColB| ColC
_____________________________
NaN | B4 | C1
NaN | B4 | C2
NaN | B1 | C3
...... | .... | ....
NaN | B39 | C(n-1)
NaN | B74 | Cn
df2 has n rows and 2 columns (A and B) :
ColA|ColB
____________________
A1 | B1
A2 | B2
A3 | B3
.... | ....
A(n-1) | B(n-1)
An | Bn
The goal here is to fill the A column from df1 thanks to df2 and to get a dataframe like this :
df1 wanted :
ColA|ColB| ColC
_____________________________
A4 | B4 | C1
A4 | B4 | C2
A1 | B1 | C3
.... | .... | ....
A74 | B74 | Cn
I tried a lot of things (double for loops, pandas methods, etc.) but nothing worked. I think I don't have enough experience.
Someone can direct me towards the good way to solve the issue ?
Thanks !
Bilsix.
I'm a newbie in Python and I need your help.
I tried to search my answer in the forum but I think I don't have the good keywords... It's a shame because the issue seems to be simple (but I'm even not sure of this !). Here's the problem :
I work with 2 dataframes df1 and df2.
df1 has n rows and 3 columns (A has only "NaN") :
ColA |ColB| ColC
_____________________________
NaN | B4 | C1
NaN | B4 | C2
NaN | B1 | C3
...... | .... | ....
NaN | B39 | C(n-1)
NaN | B74 | Cn
df2 has n rows and 2 columns (A and B) :
ColA|ColB
____________________
A1 | B1
A2 | B2
A3 | B3
.... | ....
A(n-1) | B(n-1)
An | Bn
The goal here is to fill the A column from df1 thanks to df2 and to get a dataframe like this :
df1 wanted :
ColA|ColB| ColC
_____________________________
A4 | B4 | C1
A4 | B4 | C2
A1 | B1 | C3
.... | .... | ....
A74 | B74 | Cn
I tried a lot of things (double for loops, pandas methods, etc.) but nothing worked. I think I don't have enough experience.
Someone can direct me towards the good way to solve the issue ?
Thanks !
Bilsix.