[Python] Pandas create date time column based on other column with relative milliseconds time

Discussão em 'Python' iniciado por Stack, Agosto 28, 2025.

  1. Stack

    Stack Membro Participativo

    My original data csv file columns looks like this:

    | Millisec_diff | Value1 | Value2 |
    | ------------- | ------ | ------ |
    | 0 | 100 | 200 |
    | 0.005 | 101 | 20.1 |
    | 0.01 | 103 | 20.1 |
    | 0.015 | 104 | 24.1 |
    | 0.02 | 103 | 40.1 |


    I would like to create a column with date time in ISO 8601 format based on current time + timedelta based on Millisec_diff.

    I tried:

    start = datetime.today()
    df['time'] = (
    datetime(start.year, start.month, start.day,start.hour, start.minute, start.second, start.microsecond)
    + pandas.to_timedelta(df['Millisec_diff '], unit='ms')
    )


    Which generated a time column, but value is the same. I wanted to generate time with difference as per Millisec_diff. Thanks.

    Continue reading...

Compartilhe esta Página