我有一个条目表,如下所示。该表缺少日期条目,我想用月末缺少的日期值填充这些条目。对于第一列,添加的缺失日期条目行应填充相同的值,对于值列,我希望它们填充为 0。
FirstName MiddleName LastName Date Value1 Value2 Value3
first1 middle1 last1 1/31/2020 51 80 19
first1 middle1 last1 2/29/2020 14 44 56
first1 middle1 last1 4/30/2020 57 96 40
first1 middle1 last1 6/30/2020 58 65 3
first1 middle1 last1 8/31/2020 1 34 4
first1 middle1 last1 10/31/2020 40 38 53
first1 middle1 last1 12/31/2020 93 65 41
first1 middle1 last1 2/28/2021 3 43 0
first1 middle1 last1 4/30/2021 46 61 52
first2 middle2 last2 1/31/2020 64 19 33
first2 middle2 last2 2/29/2020 28 71 16
first2 middle2 last2 4/30/2020 2 94 78
first2 middle2 last2 5/31/2020 78 99 87
first2 middle2 last2 6/30/2020 10 70 14
first2 middle2 last2 7/31/2020 30 30 59
first2 middle2 last2 8/31/2020 55 96 73
first2 middle2 last2 10/31/2020 22 43 23
first2 middle2 last2 11/30/2020 12 4 84
first2 middle2 last2 1/31/2021 59 93 1
first2 middle2 last2 2/28/2021 19 33 52
first2 middle2 last2 3/31/2021 46 12 97
first2 middle2 last2 4/30/2021 41 44 59
first2 middle2 last2 5/31/2021 67 84 96
first2 middle2 last2 6/30/2021 52 69 78
first3 middle3 last3 4/30/2020 5 63 30
first3 middle3 last3 5/31/2020 45 22 7
first3 middle3 last3 6/30/2020 76 2 33
first3 middle3 last3 8/31/2020 81 25 52
first3 middle3 last3 9/30/2020 55 3 32
first3 middle3 last3 11/30/2020 46 45 80
first3 middle3 last3 12/31/2020 17 81 74
first3 middle3 last3 1/31/2021 98 6 55
'''
预期产出
FirstName MiddleName LastName Date Value1 Value2 Value3
first1 middle1 last1 1/31/2020 51 80 19
first1 middle1 last1 2/29/2020 14 44 56
first1 middle1 last1 3/31/2020 0 0 0
first1 middle1 last1 4/30/2020 57 96 40
first1 middle1 last1 5/31/2020 0 0 0
first1 middle1 last1 6/30/2020 58 65 3
first1 middle1 last1 7/31/2020 0 0 0
first1 middle1 last1 8/31/2020 1 34 4
first1 middle1 last1 9/30/2020 0 0 0
first1 middle1 last1 10/31/2020 40 38 53
first1 middle1 last1 11/30/2020 0 0 0
first1 middle1 last1 12/31/2020 93 65 41
first1 middle1 last1 1/31/2021 0 0 0
first1 middle1 last1 2/28/2021 3 43 0
first1 middle1 last1 3/31/2021 0 0 0
first1 middle1 last1 4/30/2021 46 61 52
first2 middle2 last2 1/31/2020 64 19 33
first2 middle2 last2 2/29/2020 28 71 16
first2 middle2 last2 3/31/2020 0 0 0
first2 middle2 last2 4/30/2020 2 94 78
first2 middle2 last2 5/31/2020 78 99 87
first2 middle2 last2 6/30/2020 10 70 14
first2 middle2 last2 7/31/2020 30 30 59
first2 middle2 last2 8/31/2020 55 96 73
first2 middle2 last2 9/30/2020 0 0 0
first2 middle2 last2 10/31/2020 22 43 23
first2 middle2 last2 11/30/2020 12 4 84
first2 middle2 last2 12/31/2020 0 0 0
first2 middle2 last2 1/31/2021 59 93 1
first2 middle2 last2 2/28/2021 19 33 52
first2 middle2 last2 3/31/2021 46 12 97
first2 middle2 last2 4/30/2021 41 44 59
first2 middle2 last2 5/31/2021 67 84 96
first2 middle2 last2 6/30/2021 52 69 78
first3 middle3 last3 4/30/2020 5 63 30
first3 middle3 last3 5/31/2020 45 22 7
first3 middle3 last3 6/30/2020 76 2 33
first3 middle3 last3 7/31/2020 0 0 0
first3 middle3 last3 8/31/2020 81 25 52
first3 middle3 last3 9/30/2020 55 3 32
first3 middle3 last3 10/31/2020 0 0 0
first3 middle3 last3 11/30/2020 46 45 80
first3 middle3 last3 12/31/2020 17 81 74
first3 middle3 last3 1/31/2021 98 6 55
我尝试将重采样与数据框一起使用,但没有得到所需的输出。df = df.set_index('Date').resample('M').ffill().reset_index()