来自excel的不可理解的内容loadtxt csv

时间:2017-06-06 20:09:30

标签: arrays regex numpy

1)下面给出了txt文件:

enter image description here

2)直接导入数组:

from numpy import loadtxt

def TestImport():
    HeadersPath = 'C:/mypath/Headers_20170602.txt'
    Header = loadtxt(HeadersPath,dtype=str,delimiter="/t" )

    print Header

TestImport()

3)给我以下输出:

%run "C:/mypath/TestCSVImport.py"
['\xff\xfe1\x00\t\x002\x00\t\x003\x00\t\x004' '' '']

为什么我看不到1,2,3,4?

1 个答案:

答案 0 :(得分:0)

考虑使用Pandas模块:

import pandas as pd

arr = pd.read_csv(r'/path/to/file.csv', sep='\t', header=None).values

或:

arr = pd.read_csv(r'/path/to/file.csv', sep='\t', header=None, encoding='utf-16').values