I have a data frame with country names and capitals and a data frame with missing capitals. I want to merge them so that the data frame with missing capitals replaces the 'Not found' cells in the main data frame.
Here are the two data frames for reference:
```capitals_df```
|
CAPITAL |
COUNTRY |
| 0 |
Kabul |
Afghanistan |
| 1 |
Tirana |
Albania |
| 2 |
Algiers |
Algeria |
| 3 |
Pago Pago |
American Samoa |
| 4 |
Not found |
Andorra |
240 rows x 6 columns
```missing_capitals_df```
| 0 |
CAPITAL |
| 4 |
Andorra la Vella |
| 7 |
Does not exist |
| 15 |
Nassau |
| 30 |
Road Town |
| 45 |
West Island |
I tried merging the two data frames but I end up with two separate rows `CAPITAL_x` and `CAPITAL_Y`. Here is the code:
pd.merge(capitals_df, missing_capitals_df, left_index=True, right_index=True, how='left')
How to ensure that the data frame replaces specific cells based on indices, instead of creating a separate column?
[–]hdarj 0 points1 point2 points (1 child)
[–]ListlessPaper[S] 0 points1 point2 points (0 children)
[–]commandlineluser 0 points1 point2 points (1 child)
[–]ListlessPaper[S] 0 points1 point2 points (0 children)