Answer the question
In order to leave comments, you need to log in
How to read data from .csv file in numpy skipping non-numeric values?
I have a CSV file
5.8497e-001, 1.4380e-001, -8.1657e-003, 3.9700e+002
5.8468e-001, 1.4616e-001, -8.2995e-003, 3.9782e+002
5.8794e-001, 1.4496e-001, -8.2315e-003, 4.0057e+002
5.8548e-001, 1.5401e-001, -8.7451e-003, 3.9863e+002
[Name]
Nv
[Data]
X [ m ], Y [ m ], Z [ m ], T [ K ]
5.7816e-001, 1.0110e-001, -7.7954e-004, 3.7772e+002
5.7858e-001, 1.0105e-001, -5.7192e-004, 3.7812e+002
np.loadtxt(path, delimiter=',')
Answer the question
In order to leave comments, you need to log in
You can use np.genfromtxt(), you can pass it an array of only the necessary lines, throwing out all the unnecessary ones in advance. In the simplest case, you can do this (if you want to use a more accurate check of numbers):
nums = '-0123456789'
# выбираем только цифровые строки
lines = [line for line in csv_file.readlines() if line[0] in nums]
data = np.genfromtxt(lines, delimiter=",")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question