How do i load a specific column of information from a table into an array in Python?
Question: So, i'm supposed to load information from the SORCE database using a url with
variables for the begin and end date of information and then create an array
for the wavelength.

i'm saving the data using:

    
    
       url = "http://lasp.colorado.edu/lisird/tss/sorce_ssi.csv?&time>=%(YYYY)04d-%(MM)02d-%(DD)02d&time<%(yyyy)04d-%(mm)02d-%(dd)02d" %{"YYYY":YYYY, "MM":MM, "DD":DD, "yyyy":yyyy, "mm":mm, "dd":dd}
    urlptr = urllib2.urlopen(url)
    data = ascii.read(urlptr)
    

this gets an output like:

    
    
    time (days since 2003-01-24) wavelength (nm) ... instrument (id) version
    ---------------------------- --------------- ... --------------- -------
                          2534.5             0.5 ...            57.0    10.0
                          2534.5             1.5 ...            57.0    10.0
                          2534.5             2.5 ...            57.0    10.0
                          2534.5             3.5 ...            57.0    10.0
                          2534.5             4.5 ...            57.0    10.0
                          2534.5             5.5 ...            57.0    10.0
                          2534.5             6.5 ...            57.0    10.0
                          2534.5             7.5 ...            57.0    10.0
                          2534.5             8.5 ...            57.0    10.0
                          2534.5             9.5 ...            57.0    10.0
                          2534.5            10.5 ...            57.0    10.0
                             ...             ... ...             ...     ...
                          2898.5         2300.43 ...             nan     nan
                          2898.5         2311.89 ...             nan     nan
                          2898.5         2323.28 ...             nan     nan
                          2898.5         2334.63 ...             nan     nan
                          2898.5          2345.9 ...             nan     nan
                          2898.5         2357.11 ...             nan     nan
                          2898.5         2368.28 ...             nan     nan
                          2898.5         2379.37 ...             nan     nan
                          2898.5         2390.42 ...             nan     nan
                          2898.5          2401.4 ...             nan     nan
                          2898.5         2412.34 ...             nan     nan
    

and my first thought to create the wavelength array was to write something
like:

    
    
    wlength = loadtxt(data, usecols=(1))
    

However, when i run this i get a type error saying that the 'int' object isn't
iterable.

I know that ints aren't iterable, but how do i make the information i'm
looking for into something that is iterable?


Answer: Here's an example using the csv module:

    
    
    import csv
    import urllib2
    
    wavelengths = []
    # small time range for example
    url = "http://lasp.colorado.edu/lisird/tss/sorce_ssi.csv?&time%3E=2014-01-01&time%3C2014-01-10"
    urlptr = urllib2.urlopen(url)
    
    csv_reader = csv.reader(urlptr)
    first_line = True
    for row in csv_reader:
        if first_line:
            first_line = False
            continue
        wavelengths.append(row[1])
    
    print "There's", len(wavelengths), "wavelengths"
    print "First 10", wavelengths[:10]
    

