[Python] Change in date from string to datetime object when converting pandas dataframe to...

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

  1. Stack

    Stack Membro Participativo

    I have the foll. dataframe:

    avi fi_id dates
    2017-07-17 0.318844 zab_a_002 2017-07-17


    When I convert it into a dictionary, I get this:

    dict_avi = df.reset_index().to_dict('records')

    [{'index': Timestamp('2017-07-17 00:00:00'), 'avi': 0.3188438263036763, 'fi_id': 'zab_a_002', 'dates': datetime.date(2017, 7, 17)}]


    Why did the dates column become a datetime object? How can I retain it as a string?

    Here are the dtypes:

    avi float64
    fi_id object
    dates object
    dtype: object

    Continue reading...

Compartilhe esta Página