I have a dataframe like this:
Time
07:20:45
05:19:41
10:16:26
10:54:10
I want to remove leading zeros from the Time column:
Time
7:20:45
5:19:41
10:16:26
10:54:10
The code I’m using:
df1['Time'] = df1['Time'].apply(lambda x: x.lstrip('0'))
Error it’s throwing:
AttributeError: ‘datetime.time’ object has no attribute ‘lstrip’
>Solution :
What ever the reason is to do that, in this case you could cast the pandas object to a string, so stripping will be possible:
df1['Time'] = df1['Time'].astype('str').apply(lambda x: x.lstrip('0'))