1

I have a problem with reading in a CSV file with # signs. The CSV looks like this.

 aaa;;xxx;aaa;aaa;aaa;xxx;xxx;xxx;xxx;xxx;xxx;aaa

with aaa as a string and xxx as float. But in this file there is a line like this:

aaa;;aaa;#N/A;#N/A;#N/A;#N/A;#N/A;#N/A;#N/A;#N/A;#N/A;#N/A

Python keeps saying that this line would have 4 columns instead of 13. He interprets the # as a comment and skips the rest of it. I tried:

kwargs = dict(delimiter=';',
          dtype=np.str,
          skip_header=11,
          usecols= range(1,14),
          missing_values = "#N/A",
          filling_values = "0")
data = np.genfromtxt(TestFile, **kwargs)

but still couldn't get it to work.

How could I manage that?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Toggo
  • 127
  • 1
  • 7

1 Answers1

0

Change the dictionary to,

kwargs = dict(delimiter=';',
              dtype=np.str,
              skip_header=11,
              usecols= range(1,14),
              missing_values = "#N/A",
              filling_values = "0",
              comments=None)

Now, this should work. However, I'm not sure why you're using columns 1-13 when there are only columns from 0-12.

JerryTheo
  • 91
  • 5
  • Thank you for your answer. This works for me. I am reading columns 1-13 because the real csv has more columns... – Toggo Nov 10 '17 at 14:55