[Python] Panda Resampling is incorrect for some cases

Discussão em 'Python' iniciado por Stack, Janeiro 22, 2025.

  1. Stack

    Stack Membro Participativo

    I have problem with resample function it's work with some timeframes and doesn't work with others

    it doesn't work with 5h or 10h intervals, it's start okay and then it's changed to wrong datetime

    d = {'Open': 'first', 'High': 'max', 'Low': 'min', 'Close': 'last'}
    df = read.resample('5H').agg(d)
    df


    output:

    Open High Low Close
    Date
    2024-01-21 00:00:00 317.3 319.5 316.1 317.4
    2024-01-21 05:00:00 317.4 319.4 317.2 319.0
    2024-01-21 10:00:00 319.0 319.6 318.0 319.1
    2024-01-21 15:00:00 319.1 321.6 317.5 320.6
    2024-01-21 20:00:00 320.6 321.7 318.2 319.5
    2024-01-22 01:00:00 319.5 320.1 314.1 317.2
    2024-01-22 06:00:00 317.2 318.6 310.7 312.8
    2024-01-22 11:00:00 312.8 315.3 308.4 311.1
    2024-01-22 16:00:00 311.2 312.5 303.6 308.5
    2024-01-22 21:00:00 308.5 308.7 304.8 308.2
    2024-01-23 02:00:00 308.1 311.7 308.1 309.9
    2024-01-23 07:00:00 310.0 310.2 291.7 295.9


    It's start okay until the next day 2024-01-22

    and it's work correctly with 2h or 3h or 4h or 6h intervals

    d = {'Open': 'first', 'High': 'max', 'Low': 'min', 'Close': 'last'}
    df = read.resample('4H').agg(d)
    df


    output:

    2024-01-21 00:00:00 317.3 319.5 316.1 318.5
    2024-01-21 04:00:00 318.5 318.9 317.2 317.5
    2024-01-21 08:00:00 317.5 319.6 317.3 319.3
    2024-01-21 12:00:00 319.3 319.6 317.5 318.9
    2024-01-21 16:00:00 318.9 321.6 317.9 320.6
    2024-01-21 20:00:00 320.6 321.7 318.2 318.6
    2024-01-22 00:00:00 318.7 320.3 315.3 316.7
    2024-01-22 04:00:00 316.7 318.6 314.1 317.8
    2024-01-22 08:00:00 317.9 317.9 310.7 313.5
    2024-01-22 12:00:00 313.4 315.3 308.4 311.1
    2024-01-22 16:00:00 311.2 312.5 303.6 306.6

    Continue reading...

Compartilhe esta Página