I have two dataframes with same dates which could be used as index. The two dataframes look like below:
| date | value1 |
|---|---|
| 2022-01-01 | 1 |
| 2022-01-02 | 2 |
| date | value2 |
|---|---|
| 2022-01-01 | 1 |
| 2022-01-01 | 2 |
| 2022-01-02 | 3 |
| 2022-01-02 | 4 |
I want to add a new column in the 2nd dataframe. The value of the new column should be the value2 divided by value 1 with the same date, so it will be:
| date | value2 | new column |
|---|---|---|
| 2022-01-01 | 1 | 1(1/1) |
| 2022-01-01 | 2 | 2(2/1) |
| 2022-01-02 | 3 | 1.5(3/2) |
| 2022-01-02 | 4 | 2(4/2) |
Currently I'm using a loop to do so. By doing some research I think there should be a more "dataframe way" though I don't figure it out yet.