[Python] Pandas resample: when resampling from hours to quarterhours, the last three...

Discussão em 'Python' iniciado por Stack, Maio 12, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to resample an hourly pandas DataFrame to one with a quarterhourly index. It is left-labeled, so when the index says DD-mm-YYYY 10:00, it indicates the hour 10:00 to 11:00. However, if I do this, the last three quarterhours of the last hour are missing. Code example:

    import datetime
    import pandas as pd

    start_date = datetime.datetime(2025, 5, 12, 10)
    index = pd.date_range(start=start_date, periods=3, freq="h")

    asd = pd.DataFrame(data=[1, 2, 3], index=index)

    asd_qh = asd.resample("15min").ffill()
    print(asd_qh)


    The last rows are:

    [..]
    2025-05-12 11:30:00 2
    2025-05-12 11:45:00 2
    2025-05-12 12:00:00 3


    but they should be:

    [..]
    2025-05-12 11:30:00 2
    2025-05-12 11:45:00 2
    2025-05-12 12:00:00 3
    2025-05-12 12:15:00 3
    2025-05-12 12:30:00 3
    2025-05-12 12:45:00 3

    Continue reading...

Compartilhe esta Página