-1

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?

Amanda_Panda
  • 1,156
  • 4
  • 26
  • 68

2 Answers2

0

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

  • 1
    5 OccurTime 59528 non-null int64 – Amanda_Panda Sep 25 '21 at 17:22
  • you can convert int dateTime to datetime format easily using: `import pandas as pd df2 = pd.DataFrame({'int_date': [20210101, 20210102, 20210103]}) df2['formatted_date'] = pd.to_datetime(df2['int_date'].astype(str), format='%Y%m%d') print(df2)` But, I think this column is not for dateTime, It seems the count of occurrence(repeat) of this record event. Can you please check again the business behind this column? – Basem Torky Sep 25 '21 at 17:36
  • @Amanda_Panda Do you still need support here? – Basem Torky Sep 27 '21 at 11:34
  • Nope, gonna accept my own comment below as the answer in about an hour. Thank you for your help! – Amanda_Panda Sep 27 '21 at 15:50
0

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

Amanda_Panda
  • 1,156
  • 4
  • 26
  • 68