Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

import dataframe with milliseconds in timestamp

I got a file, which contains a timestamp like ’15:05:26:811′.

If I try to import it into pandas with

data = pd.read_csv(file, sep='\t', names=['Time', 'x-data', index_col = False, dtype = float)

I get the error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ValueError: could not convert string to float: '15:05:26:811'

What do I have to do? Just remove "dtype = float"? This might work, but will this lead to problems?

>Solution :

You can parse the string column to a datetime object after reading the csv:

data['Time'] = pd.to_datetime(data['Time'], format='%H:%M:%S:%f')

If you want to parse the string while reading the csv, add a dedicated parser: https://stackoverflow.com/a/17468012/5316326

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading