0

I've been struggling with merging DataFrames. I have two DataFrames. I call them dfA and dfB here and dfA has timestamp key and dfB has timestamp column and row that contains the counting number of each dates in dfB. Their dates format is same like "2021-05-05" but some of dates are lacked in dfB . What I want to do is finding out which dates are lacked in dfB by comparing to dfA and updating the dates into dfB and 0 or null as a value in order . Could anyone give me advice ?? Thank you so much.

Below is one of my code I tried

pd.concat([dfA.set_index('timestamp'), dfB], axis=1)
⇩
[92 rows x 1 columns]
              count
0                3
1               20
2               24
3               21
4               14
5                5
6               14
7               16
8               17
9               14
10              78
11              20
12              78
13              13
14              21
15               8
16              12
17              18
18               8
...................
dfA

     timestamp
0   2021-05-07
1   2021-05-08
2   2021-05-09
3   2021-05-10
4   2021-05-11
..         ...
87  2021-05-31
88  2021-06-01
89  2021-06-02
90  2021-05-21
91  2021-06-02
dfB

     timestamp           count
0   2021-05-07               3
1   2021-05-08              20
2   2021-05-09              24
3   2021-05-12              21
4   2021-05-13              14
..         ...             ...
81  2021-05-29               1
82  2021-05-30               1
83  2021-05-31               3
84  2021-06-01               1
85  2021-05-21               1
ideal output

     timestamp  count
# 0  2021-05-07   17.0
# 1  2021-05-08   14.0
# 2  2021-05-09   13.0 
# 3  2021-05-10    NaN ← existing only in dfA
# 4  2021-05-11    NaN ← existing only in dfA
# 5  2021-05-12   20.0
okkotsu
  • 137
  • 10

0 Answers0