1

So basically I want to add two columns with:

```
month1['Energy stop (wh)'] += diff
month1['Energy consumed (wh)'] += diff
```
| Index |     Values| 
| :---- |      ----:| 
| 17634 |     2735.0| 
| 2     |     5433.0|
| 17639 |      811.0| 
| 4     |     6116.0| 
| 8     |    12247.0| 
|       |           | 
| 17618 |    11047.0| 
| 35171 |     2249.0| 
| 17633 |    12565.0| 
| 35172 |    11158.0| 
| 35204 |     3600.0| 
Name: Energy consumed (wh), Length: 2053, dtype: float64

and I want to add a column with less values, not every value of the first table(above) is in the one I want to add.

| Index|    Values| 
| :----|    ----: | 
| 3    |     30300| 
| 4    |     46450| 
| 5    |     42751| 
| 7    |     14682| 
| 10   |      7526| 
| 1847 |    181066| 
| 1865 |     44012| 
| 1878 |    356825| 
| 1879 |     34404| 
| 1891 |    -17275| 
Length: 171, dtype: int64

how can I add those two Dataframes without touching the values that are not in both tables?

Thanks in advance

1 Answer 1

1

You can use an outer merge on the column Index like so :

df = pd.merge(df1,
              df2,
              how='outer',
              left_on=['Index'],
              right_on=['Index'])

If Index is the actual index for both DataFrames, you might rather use left_index and right_index :

df = pd.merge(df1,
              df2,
              how='outer',
              left_index=True,
              right_index=True)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.