I have a little problem when I try to import data from CSV files with the numpy loadtxt function. Here is an example of the type of data files that I have.
Name it 'datafile1.csv':
# Comment 1
The script that I thought would work for this situation is as follows:
import numpy as np FH = np.loadtxt('datafile1.csv',comments='#',delimiter=',',skiprows=1)
But I get an error message:
ValueError: could not convert string to float: x
This tells me that kwarg "skiprows" does not skip the title, it skips the first line of comments. I could just make sure skiprows = 3, but the complication is that I have a very large number of files, which not all have the same number of commented lines at the top of the file. How can I make sure that when I use loadtxt, I only get the actual data in this situation?
PS - I am open to bash solutions.
astromax
source share