I have a two dataframe that have the same rows and columns in python, I want to join with the following condition.
Mainteain the same structure of df_a, introduce de value of the df_b just in the cells with "x" value of the df_a
df_a =
| 2022 | 2023 | 2024 | 2025 | 2026 | 2027 |
|---|---|---|---|---|---|
| x | x | x | nan | nan | nan |
| nan | nan | x | x | nan | nan |
| nan | x | x | x | x | x |
df_b =
| 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|
| 4 | 7 | 8 | nan | nan | nan |
| 5 | 8 | nan | nan | nan | nan |
| 6 | 9 | 4 | 3 | 2 | nan |
The final dataframe would be
df_final =
| 2022 | 2023 | 2024 | 2025 | 2026 | 2027 |
|---|---|---|---|---|---|
| 4 | 7 | 8 | nan | nan | nan |
| nan | nan | 5 | 8 | nan | nan |
| nan | 6 | 9 | 4 | 3 | 2 |
Many thanks in advance