读取CSV文件后,列中掩盖了特定值
在阅读CSV文件后,我很难找到正确的方法来掩盖列的特定值。我找到了如何在代码中直接创建数组后创建蒙版数组。
如果我正在阅读文件 data = np.genfromtxt(“ file”)
我想掩盖标有“年龄”的列中的所有“ na”条目,我将如何写出?提前致谢!
I'm having trouble finding the correct way to mask specific values from a column after reading a csv file. I found how to create a masked array after creating an array directly in the code.
If I'm reading a file withdata = np.genfromtxt("file")
and I want to mask all the "NA" entries from the column labeled "Age", how would I write that out? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建
np.ma.array
,然后使用Mean
获得所需的结果。 结果np.ma.Array中的掩码
可以设置为arr.isnan()
的 参考的链接:https://numpy.org/numpy.org/doc /stable/reference/generated/numpy.ma.mean.html
You could create
np.ma.array
and then usemean
to get the desired result. The mask in thenp.ma.array
could be set to the result ofarr.isnan()
which would mask allNAN
valuesHere is the link for reference:
https://numpy.org/doc/stable/reference/generated/numpy.ma.mean.html