pandas 如何在数据帧熊猫中将 0 替换为空值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43654011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 03:29:33 来源:igfitidea点击:
How to replace 0 to null value in dataframe pandas?
提问by Shi Jie Tio
I have a dataframe, some of the cell in the dataframe have 0 , how to replace all the 0 with ' ' ?
我有一个数据帧,数据帧中的一些单元格有 0 ,如何用 ' ' 替换所有的 0 ?
final = final.replace(0, '')
This code not able run...Anyone can share me idea?
此代码无法运行...任何人都可以分享我的想法吗?
回答by jezrael
I think you need:
我认为你需要:
final = final.replace(0, np.nan)
.style.apply(color, axis=None)
.set_table_attributes('border="" class = "dataframe table table-hover table-bordered"')
.set_precision(10)
.render()