1)下面给出了txt文件:
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?
答案 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