[Python] Pandas - Change AM/PM format to 24h

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

  1. Stack

    Stack Membro Participativo

    I have some time input in the format of '10:23:34 PM' in string and I'd like to convert it to a datetime looking like '22:23:45'. I'm using

    datetime = posts['time'].apply(lambda x: datetime.strptime(x, '%I:%M:%S %p').strftime('%I:%M:%S'))


    However, this seems to disregard the AM/PM markers, and all the info comes out as if the time was in the AM, ergo for the '10:23:34 PM' input I get '10:23:34' as output, but it should be '22:23:45'. How can I fix this?

    Continue reading...

Compartilhe esta Página