python - Pandas read_csv reading time offset strings -
i have text file data columns '10:15.3' meaning 10 minutes 15.3 seconds after canonical event. when read read_csv, i'm getting strings:
>>> df.time.head() 0 08:32.0 1 08:38.0 2 08:39.0 3 08:43.0 4 09:15.0 name: time, dtype: object >>> df.time.head()[:1][0] '08:32.0' >>>
i feel should able seconds enough within pandas, either specifying conversion in read_csv or (probably better, have both) appending new column, i'm not seeing how it. i'm pretty sure me being dense.
can offer tip me unstuck?
you can use datetime.time
object. provide: hours, minutes, seconds, microseconds. these provided integers, need int cast relevant part of each string datetime.date constructor.
so in case:
import datetime df = pd.read_csv('your_csv.csv') df.time = pd.series([datetime.time(0, int(val[:2]), int(val[3:5]), int(val[6:])*100000) val in df.time], index = df.index)
Comments
Post a Comment