首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用python中的for循环填充NaN值

如何使用python中的for循环填充NaN值
EN

Stack Overflow用户
提问于 2022-04-20 15:30:29
回答 1查看 157关注 0票数 -1

我必须为h列做这个吗?

代码语言:javascript
复制
    a   b   c   d   e   f   g   h   j
0   mid low excellent   mid stable  stable  NaN 15.0    A
1   mid high    excellent   NaN unstable    stable  stable  10.0    S
2   high    low excellent   high    stable  stable  mod-stable  10.0    A
3   mid NaN good    high    stable  unstable    mod-stable  NaN A
4   mid mid excellent   high    stable  stable  stable  10.0    A
5   high    low good    NaN stable  stable  unstable    15.0    S
6   mid low excellent   high    stable  stable  mod-stable  5.0 S
7   high    mid excellent   mid unstable    unstable    stable  10.0    S
8   mid high    good    mid stable  stable  stable  10.0    S
9   mid low excellent   mid unstable    stable  mod-stable  10.0    S
EN

回答 1

Stack Overflow用户

发布于 2022-04-20 15:37:58

用什么手段?如果您使用熊猫或numpy,您可以检查值是pd.NA还是np.nan。如果你像对待文本一样对待它,你可以尝试用str.split来分割它。

代码语言:javascript
复制
for row in rows:
    fields = row.split(delim)
    if fields[7] == 'NaN':
        fields[7] = str(mean)
    row = fields.join(delim)

文件中使用的delim分隔符

或者其他类似的东西。希望这能回答你的问题,但我不知道你想做什么。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71942380

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档