I have several different data files that I need to import using genfromtxt. Each data file has different content. For example, file 1 may have all floats, file 2 may have all strings, and file 3 may have a combination of floats and strings etc. Also the number of columns vary from file to file, and since there are hundreds of files, I don't know which columns are floats and strings in each file. However, all the entries in each column are the same data type.
Is there a way to set up a converter for genfromtxt that will detect the type of data in each column and convert it to the right data type?
Thanks!
pandas.readcsvis much more powerful thannumpy.genfromtxt, and will do all of this for you automatically.dataframe.to_records()will give you a record array, which is probably what you want then. Storing mixed types in a numpy array can only be done via a record array or an object array.