pandas 用空白/空字符串替换NaN [英] Pandas Replace NaN with blank/empty string

查看:137
本文介绍了 pandas 用空白/空字符串替换NaN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Pandas数据框,如下所示:

I have a Pandas Dataframe as shown below:

    1    2       3
 0  a  NaN    read
 1  b    l  unread
 2  c  NaN    read

我想用一个空字符串删除NaN值,使其看起来像这样:

I want to remove the NaN values with an empty string so that it looks like so:

    1    2       3
 0  a   ""    read
 1  b    l  unread
 2  c   ""    read

推荐答案

import numpy as np
df1 = df.replace(np.nan, '', regex=True)

这可能会有所帮助.它将用一个空字符串替换所有NaN.

This might help. It will replace all NaNs with an empty string.

这篇关于 pandas 用空白/空字符串替换NaN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆