Genfromtxt not working


For some reason I can’t get it to import the csv in the numpy review

I have:

import numpy as np

temperature = np.genfromtxt(‘temperature_data.csv’, ‘,’)

and its giving me this error:

Traceback (most recent call last):
File “”, line 3, in
temperature = np.genfromtxt(‘temperature_data.csv’, ‘,’)
File “/usr/local/lib/python2.7/dist-packages/numpy/lib/”, line 1619, in genfromtxt
File “/usr/local/lib/python2.7/dist-packages/numpy/lib/”, line 904, in easy_dtype
ndtype = np.dtype(dict(formats=ndtype, names=names))
TypeError: data type “,” not understood

Why doesn’t it like comma as a delimiter?


In asking that, you’re assuming it’s used as a delimiter (restricting the possible number of answers to 0 if the receiver of the question doesn’t agree with it)

The error message says what it’s used as. You can also look up the signature of the function either from within python itself or through documentation if any such exists outside the source itself

genfromtxt(fname, dtype=<class 'float'>, comments='#', delimiter=None, skip_header=0, skip_footer=0, conve
rters=None, missing_values=None, filling_values=None, usecols=None, names=None, excludelist=None, deletech
ars=None, replace_space='_', autostrip=False, case_sensitive=True, defaultfmt='f%i', unpack=None, usemask=
False, loose=True, invalid_raise=True, max_rows=None, encoding='bytes')                                  
    Load data from a text file, with missing values handled as specified.                                

    Each line past the first `skip_header` lines is split at the `delimiter`                             
    character, and characters following the `comments` character are discarded.                          

    fname : file, str, pathlib.Path, list of str, generator                                              
        File, filename, list, or generator to read.  If the filename                                     
        extension is `.gz` or `.bz2`, the file is first decompressed. Note                               
        that generators must return byte strings in Python 3k.  The strings                              
        in a list or produced by a generator are treated as lines.                                       
    dtype : dtype, optional
        Data type of the resulting array.
        If None, the dtypes will be determined by the contents of each                                   
        column, individually.
    comments : str, optional
        The character used to indicate the start of a comment.                                           
        All the characters occurring on a line after a comment are discarded                             
    delimiter : str, int, or sequence, optional
        The string used to separate values.  By default, any consecutive                                 
        whitespaces act as delimiter.  An integer or sequence of integers                                
        can also be provided as width(s) of each field.          


yeah… im just an idiot and left out delimiter=


But we make mistakes. Can’t do very much about that.
We can look at the outcome (the error message), and we can compare to what the code was supposed to be (documentation) and from there figure out what the problem is.

Forget about writing everything correctly. It’s all about fixing it.

(Obviously not entirely true, we can get more accurate… But never accurate.)