Pandas无法读取csv文件,它全部替换为NaN

时间:2017-09-22 10:26:49

标签: python pandas csv

我尝试阅读csv文件

 df = pd.read_csv("raccoons.csv", delimiter=":")
 df.head()

然后它回到我身边

 ��c    Unnamed: 1  Unnamed: 2
 NaN    NaN     NaN     NaN
 NaN    NaN     NaN     NaN
 NaN    NaN     NaN     NaN
 NaN    NaN     NaN     NaN
 NaN    NaN     NaN     NaN

文件内

corrds:time:raccoons_bought
55.771393 37.567392:4423O3138:2
55.705458 37.550926:442365718:0
55.83028 37.404815:442244596:0
55.799092 37.452157:442327511:148.00001
55.749785 37.763962:442248573:1

2 个答案:

答案 0 :(得分:1)

这可能与文件编码有关。调用read_csv时可能必须设置此设置。检查解决方案以找到此处提供的文件编码:UnicodeDecodeError when reading CSV file in Pandas with Python

我遇到了同样的问题,最后使用以下方法解决了该问题:

pd.read_csv(..., encoding = 'utf-16')

答案 1 :(得分:0)

尝试:

a = tf.constant([[11,0,13,14],
                 [21,22,23,0]])
condition = tf.equal(a, 0)
case_true = tf.reshape(tf.multiply(tf.ones([8], tf.int32), -9999), [2, 4])
case_false = a
a_m = tf.where(condition, case_true, case_false)
sess = tf.Session()
sess.run(a_m)

回答编辑。它对我有用!