Receiving Nan (not a number) when reading a file. CSV with numpy

Asked

Viewed 170 times

0

Using python 3.6.5

import numpy as np

valores = np.genfromtxt("arquivo.csv",delimiter = ";",skip_header = 1)
print(valores)

CSV file.:

Valores1,Valores2,Valores3
10,20,30
40,50,60
70,80,90
34,54,23

Exit:

array([nan, nan, nan, nan])

What’s going on?

  • 5

    It has nothing to do with passing your delimiter as ; and the CSV has as delimiter ,?

  • @Pedro von Hertwig: Thank you! I will test!

1 answer

2


As already indicated in the comments, it is only the delimiter parameter that is wrong. When changing ";" for "," the code works:

import numpy as np
valores = np.genfromtxt("arquivo.csv", delimiter=",", skip_header=1)
print(valores)

# saída:
[[10. 20. 30.]
 [40. 50. 60.]
 [70. 80. 90.]
 [34. 54. 23.]]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.