import numpy as np

filename = ‘./data/51job.csv’
arr = np.loadtxt(filename,
delimiter=’,’,
skiprows=1,
usecols=[0,1,2,3],
dtype=str,
)

print(arr)

用numpy加载包含中文的csv文件会报错:

UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0x80 in position 36: illegal multibyte sequence

numpy加载包含中文的csv文件报错的解决方法

解决办法一:

arr = np.loadtxt(filename,
delimiter=’,’,
skiprows=1,
usecols=[0,1,2,3],
dtype=str,
encoding=‘utf8’
)

print(arr)
解决办法二:

arr=np.loadtxt(open(filename, encoding=‘utf8’),
dtype=str,
delimiter=’,’,
skiprows=1)
print(arr)

相关文章:

  • 2021-09-17
  • 2022-02-23
  • 2021-12-30
  • 2021-08-03
  • 2021-11-29
  • 2022-12-23
  • 2021-06-23
  • 2022-03-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2021-07-20
  • 2021-11-24
  • 2021-11-09
  • 2022-01-16
相关资源
相似解决方案