代码之家  ›  专栏  ›  技术社区  ›  Pythoner

如何使pd.read_csv作为np.nan读取“空”?[复制品]

  •  0
  • Pythoner  · 技术社区  · 6 年前

    我有一个csv文件:

    Date,Open,High,Low,Close,Adj Close,Volume
    1980-12-12,0.513393,0.515625,0.513393,0.513393,0.023106,117258400
    1980-12-15,0.488839,0.488839,0.486607,0.486607,0.021900,43971200
    1980-12-16,0.453125,0.453125,0.450893,0.450893,0.020293,26432000
    1980-12-17,0.462054,0.464286,0.462054,0.462054,0.020795,21610400
    1980-12-18,0.475446,0.477679,0.475446,0.475446,0.021398,18362400
    1980-12-19,0.504464,0.506696,0.504464,0.504464,0.022704,12157600
    1980-12-22,null,null,null,null
    

    雷公藤多甙 无法将csv读取到数据帧中,但无法将空值传输到 NP.N. 相反,它把所有的东西都读作str。

    我可以在以后的过程中手动完成这项工作,但列类型的更改很麻烦,因为我需要逐个区分int和float,是否有任何方法可以使用read_csv最初将null作为np.nan处理?

    事先谢谢。

    1 回复  |  直到 6 年前
        1
  •  2
  •   cors    6 年前
    pd.read_csv(na_values = 'null', sep = ',')