0

I have a csv file that includes 3 columns, and I need to import it to a numpy array, respectively. The csv file is like:

Study ID     DWM     PVWM    GCA

980500221101     1   1   1

980500251101     0   0   1

980500271101     1   1   1

980500291101     1   0   0

980500301101     2   2   1

I tried

pandas : pd.read_csv('filename.csv')

and numpy : np.genfromtxt('filename.csv',delimiter=',')

and csv:

with open('filename.csv', newline='') as csvfile:
   reader = csv.DictReader(csvfile)

and got this error: charmap' codec can't decode byte 0x8d in position 639: character maps to

Dani Mesejo
  • 61,499
  • 6
  • 49
  • 76
Adam301
  • 73
  • 1
  • 11
  • Possible duplicate of [UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to ](https://stackoverflow.com/questions/9233027/unicodedecodeerror-charmap-codec-cant-decode-byte-x-in-position-y-character) – westr Oct 01 '19 at 13:28
  • Check out [`chardet.detect()`](https://chardet.readthedocs.io/en/latest/usage.html#example-using-the-detect-function); once you know the encoding, you can give that to `pd.read_csv()`. – Matt Hall Oct 01 '19 at 17:12

0 Answers0