[Python] pandas generate range of dates in Unix Timestamp

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

  1. Stack

    Stack Membro Participativo

    The dataframe I am working with contains historical stock prices and looks like this :

    timestamp open high low close volume
    0 1609459200 20830.70 21243.95 20830.7 21127.60 1663
    1 1609718400 21288.00 21300.00 21065.0 21154.65 3043
    2 1609804800 21154.65 21899.00 21011.0 21594.20 3048
    ...


    The data is for January 1, 4 and 5 2021 and there are no rows for 2nd and 3rd of January as these are Saturdays and Sundays.

    I wish to reindex this dataframe so that I can have these dates as well in my dataframe with forward filled data.

    I have found dti = pandas.date_range("2021-01-01", periods=3, freq="D") which generates dates but not as unix second timestamps. DatetimeIndex(['2021-01-01', '2021-01-02', '2021-01-03'], dtype='datetime64[ns]', freq='D')

    What is the easiest way to generate unix timestamps such as 1609459200 using pandas.

    Continue reading...

Compartilhe esta Página