'How to get rows which only have datas between each datetime scope after dataframe.resample

when I have a dataframe like below and I want to sum the value for different days:

df = pd.DataFrame([1, -1, 1, 3, 4], index=[datetime(2021, 3, 1, hour=14),
                                           datetime(2021, 3, 2, hour=14),
                                           datetime(2021, 3, 2, hour=15),
                                           datetime(2021, 3, 4, hour=14),
                                           datetime(2021, 3, 5, hour=14)])
print(df.resample('1D').sum())

The result is

            0
2021-03-01  1
2021-03-02  0
2021-03-03  0
2021-03-04  3
2021-03-05  4

But I don't want the result have the row of "2021-03-03 0", because there's no data in the original dataframe on '2021-03-03'.

So how could this to be obtained?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source