Home > Mobile >  How to read in a number from a csv as a time in Pandas
How to read in a number from a csv as a time in Pandas

Time:09-27

I have a csv that I'm trying to parse with Pandas, and there's a column that contains a 24 hour time, but it's just a simple number in the csv:

CaseNumber OccurDate OccurTime OffenseCategory OffenseType
20-X5397620 1/1/20 345 Assault Offenses Simple

The column OccurTime is what I'm trying to parse as a time

Should I join it with OccurDate so I can do the normal datetime parsing with Pandas?

CodePudding user response:

first of all, please check the "OccureTime" dataType using df.info(). for me it does not look 24H data column.

CodePudding user response:

Actually I think this answer is the one I want: Convert number to time in Python

All I'm looking for is the time, and the date part of the datetime is irrelevant for my needs.

Also this answer to help pad some of those values that are only two digits out to 4: Add Leading Zeros to Strings in Pandas Dataframe

  • Related