读取CSV文件后,列中掩盖了特定值

发布于 2025-01-21 15:19:42 字数 158 浏览 0 评论 0原文

在阅读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 with
data = 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

双手揣兜 2025-01-28 15:19:42

您可以创建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 use mean to get the desired result. The mask in the np.ma.array could be set to the result of arr.isnan() which would mask all NAN values

Here is the link for reference:

https://numpy.org/doc/stable/reference/generated/numpy.ma.mean.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文