'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
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 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
