I am using the following code in Python to transform a dataframe column of ints corresponding to hour, minute and seconds(E.g. 230100) to a time format.
data_name['Time'] = data_name['Time'].apply(lambda y: pd.to_datetime(str(y),format='%H%M%S'))
I am having the following error:
ValueError: time data '230100' does not match format '%H%M%S' (match)
The previous type of code worked perfectly to convert an int with the info YYYYMMDD.
Any ideas?
For me working nice in pandas 0.25.0, what is your pandas version? Also apply
is not necessary here:
data_name = pd.DataFrame({'Time':[230100,230100]})
data_name['Time'] = (pd.to_datetime(data_name['Time'].astype(str),
errors='coerce',
format='%H%M%S').dt.time)
print (data_name)
Time
0 23:01:00
1 23:01:00
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加