[Python] Getting Date String from Pandas automatically changing to timestamp

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

  1. Stack

    Stack Membro Participativo

    I have a pd.DataFrame which has a column entitled 'TRAN_DATE' which contains datetime.datetime objects.

    I want to change these to a specific date format "%Y-%m-%dT17:00:00". I want the date to be a changeable variable and the "T17:00:00" to remain static.

    When running the below code however I get

    for i in range(0, len(df)):
    df.loc[i,'TRAN_DATE'] = df.loc[i,'TRAN_DATE'].strftime("%Y-%m-%dT17:00:00")


    The type of the information comes back as a pandas._libs.tslibs.timestamps.Timestamp and the datetime as a whole with no T. i.e. 2024-11-11 17:00:00

    Curiously when I run the following, this produces exactly what the format looks like, but I do not want the Z. i.e. 2024-11-11T17:00:00Z

    for i in range(0, len(df)):
    df.loc[i,'TRAN_DATE'] = df.loc[i,'TRAN_DATE'].strftime("%Y-%m-%dT17:00:00Z")


    any thought

    Continue reading...

Compartilhe esta Página