human
I am working on the file "11/Parking Data.ipynb".
The first task is:
"Violation time" is... not a time. Make it a time.
Can you write Python code for it?
 ... Can you provide a the Python code you requested?
assistant
#Here is the Python code you requested.

import re
# violations_df['Violation Time'].head()

import numpy as np
# Build a function using that method
def time_to_datetime(str_time):
    try:
    #str_time = re.sub('^0', '', str_time)
        if isinstance(str_time, str):
            str_time = str_time + "M"
            #print("Trying to convert", str_time, "into a time")
            return datetime.datetime.strptime(str_time.strip(), "%I%M%p").time()
    #try:
     #   if str_time == -999:
      #      print("It's -999")
       #     return np.nan
    
    except:
        return np.nan

# Apply that method to the 'Time' column of the dataframe
violations_df['Violation Time'] = violations_df['Violation Time'].apply(time_to_datetime)

print(violations_df['Violation Time'].head())

# def remove_1900(year):
#     year = str(year)
#     year = re.sub('^1900-01-01', '', year)
#     return year

# print(violations_df['Violation Time'].apply(remove_1900))