2014-10-20 82 views
0

我想从一个CSV导入此数据文件如何解决CSV导入问题?

location scale 
 0.90109  0.63551 
0.59587  0.65525 
0.80460  0.64227 
0.65178  0.65198 
0.76307  0.64503 
0.52575  0.65915 
0.41322 0.66496 
0.30059 0.67022 
0.21620  0.67382 
0.17404 0.67552 
-0.05027 0.68363 
-0.0782 0.68454 

使用此代码。

test=[] 
import csv 
f=open("data.csv") 
for row in csv.reader(f): 
    test.append(row) 

但是当我打开测试文件时,我得到了一些\ xao编码。你能告诉我如何解决这个问题吗?

我想要做的就是在导入到变量后对数据执行一些操作。

enter image description here

+1

'.replace(u'\ xa0',u'')'first? – 2014-10-20 17:47:29

+1

或'test.append([item.replace(u'\ xa0',u'')为行]]'' – 2014-10-20 17:56:01

+0

谢谢。但现在每个数字都有一个U infront ...... – maximusyoda 2014-10-20 18:01:32

回答

2

输入文件似乎包含一些non-breaking space characters(0XA0)。从文件中删除这些文件,然后重试。

+0

是的。数据是在Excel中完成的。请帮助以编程方式删除它,因为我不知道如何在Excel中删除。 – maximusyoda 2014-10-20 18:02:10