Read in csv file with one column of strings in the middle
Question: I have a csv input file of standard format with a messy header that I am
stripping off, and then an array of 35 columns and 8760 rows. All of this data
is numeric, except the 6th column, which is text. I have tried allowing
`genfromtxt()` to figure this out on its own, but in the end that column is
turned to `nan`s, I believe because there are no quotes.

Currently, I'm reading this array as follows:

    
    
    WeaData = np.genfromtxt(FileIn, delimiter=",", skip_header=8)
    

I have tried specifying the column types manually with

    
    
    WeaData = np.genfromtxt(FileIn, delimiter=",", skip_header=8, dtype=(float,float,float,float,float,str,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float))
    

and

    
    
    WeaData = np.genfromtxt(FileIn, delimiter=",", skip_header=8, dtype=[float for n in range(5)]+['S10']+[float for n in range(29)])
    

but with no luck. I believe my syntax is wrong in the first option, and the
second returns an array of voids. Is there a simple way to do this, preferably
without specifying 35 column types?

Here are three lines of my csv file for reference, after the header I don't
care about.

    
    
    1966,1,1,1,60,A7A7A7A7*0?0?0?0?0?0?0?0A7A7A7A7A7A7F8F8A7E7,3.9,1.7,86,102400,0,0,264,0,0,0,0,0,0,0,230,2.1,0,0,24.1,77777,0,999999999,8,0.1000,0,88,0.000,0.0,0.0
    1966,1,1,2,60,A7A7A7A7*0?0?0?0?0?0?0?0A7A7A7A7A7A7F8F8A7E7,4.4,0.0,73,102500,0,0,265,0,0,0,0,0,0,0,270,3.6,0,0,24.1,77777,0,999999999,8,0.1000,0,88,0.000,0.0,0.0
    1966,1,1,3,60,A7A7A7A7*0?0?0?0?0?0?0?0A7A7A7A7A7A7F8F8A7E7,2.8,-0.6,79,102500,0,0,258,0,0,0,0,0,0,0,310,2.1,0,0,24.1,77777,0,999999999,8,0.1000,0,88,0.000,0.0,0.0
    

I'm using Python V2.7.


Answer: Use `numpy.loadtxt` with the parameter `usecols` for selecting only the
columns containing float numbers.

    
    
    >>> import numpy as np
    >>> cols = range(0,5) + range(6,35)
    >>> data = np.loadtxt("data.txt", delimiter=",", usecols=cols, dtype=np.float)
    >>> data
    [[  1.96600000e+03   1.00000000e+00   1.00000000e+00   1.00000000e+00
        6.00000000e+01   3.90000000e+00   1.70000000e+00   8.60000000e+01
        1.02400000e+05   0.00000000e+00   0.00000000e+00   2.64000000e+02
        0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
        0.00000000e+00   0.00000000e+00   0.00000000e+00   2.30000000e+02
        2.10000000e+00   0.00000000e+00   0.00000000e+00   2.41000000e+01
        7.77770000e+04   0.00000000e+00   9.99999999e+08   8.00000000e+00
        1.00000000e-01   0.00000000e+00   8.80000000e+01   0.00000000e+00
        0.00000000e+00   0.00000000e+00]
     [  1.96600000e+03   1.00000000e+00   1.00000000e+00   2.00000000e+00
        6.00000000e+01   4.40000000e+00   0.00000000e+00   7.30000000e+01
        1.02500000e+05   0.00000000e+00   0.00000000e+00   2.65000000e+02
        0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
        0.00000000e+00   0.00000000e+00   0.00000000e+00   2.70000000e+02
        3.60000000e+00   0.00000000e+00   0.00000000e+00   2.41000000e+01
        7.77770000e+04   0.00000000e+00   9.99999999e+08   8.00000000e+00
        1.00000000e-01   0.00000000e+00   8.80000000e+01   0.00000000e+00
        0.00000000e+00   0.00000000e+00]
     [  1.96600000e+03   1.00000000e+00   1.00000000e+00   3.00000000e+00
        6.00000000e+01   2.80000000e+00  -6.00000000e-01   7.90000000e+01
        1.02500000e+05   0.00000000e+00   0.00000000e+00   2.58000000e+02
        0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
        0.00000000e+00   0.00000000e+00   0.00000000e+00   3.10000000e+02
        2.10000000e+00   0.00000000e+00   0.00000000e+00   2.41000000e+01
        7.77770000e+04   0.00000000e+00   9.99999999e+08   8.00000000e+00
        1.00000000e-01   0.00000000e+00   8.80000000e+01   0.00000000e+00
        0.00000000e+00   0.00000000e+00]]
    

If you want to include the 6th column, then you will have to load the matrix
as object, you can't mix floats with strings.

    
    
    >>> data = np.loadtxt("data.txt", delimiter=",", dtype=np.object)
    

So if you need this column, load it separately.

