重命名“无"; pandas 的价值 [英] Rename "None" value in Pandas
本文介绍了重命名“无"; pandas 的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能是非常简单的,但我只是找不到答案.我使用GeoPandas从形状文件导入数据.把它变成熊猫DataFrame
.我有一个包含三个字母代码和None
值的对象字段,用于缺少数据.如何在熊猫中将None
更改为"vcv"之类的内容?我尝试过了
This is probably super simple but I just can not find the answer. I import data using GeoPandas from a shape file. Turn that into pandas DataFrame
. I have a object field with three letter codes and None
values for missing data. How do I change None
's to something like "vcv" in pandas? I tried this
sala.replace(None,"vcv")
遇到此错误
2400 "strings or regular expressions, you "
2401 "passed a"
-> 2402 " {0!r}".format(type(regex).__name__))
2403 return self.replace(regex, value, inplace=inplace, limit=limit,
2404 regex=True)
TypeError: 'regex' must be a string or a compiled regular expression or a list or dict of strings or regular expressions, you passed a 'bool'
尝试过
if sala['N10'] is None:
sala['N10'] = 'Nul'
不更改任何内容.
推荐答案
最简单的方法是:
sala['N10'].replace('None', 'vcv', inplace=True)
应该起作用.
如果它们是真实的NaN
值,则调用fillna
会起作用.
If they were true NaN
values then calling fillna
would've worked.
例如
sala['N10'].fillna(value='vcv', inplace = True)
也是我在评论中建议的内容
also what I suggested in my comment:
sala.loc[sala['N10'].isnull(), 'N10'] = 'vcv'
这篇关于重命名“无"; pandas 的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文