pandas read in csv column as float and set empty cells to 0

后端 未结 3 1212
感情败类
感情败类 2021-01-14 05:30

Is it possible to read in a CSV as a pandas DataFrame and set spaces (or empty cells) to 0 in one line? Below is an illustration of the problem.

Input:

3条回答
  •  野的像风
    2021-01-14 06:01

    df.replace(r'\s+', 0, regex=True)
    
         a  b    c
    0  0.0  a  0.0
    1  0.0  b  1.0
    2  1.5  c  2.5
    3  2.1  d  3.0
    

提交回复
热议问题