简体   繁体   English

DASK:替换单列中的无限(inf)值

[英]DASK: Replace infinite (inf) values in single column

I have a dask dataframe in which I have a few inf values appearing.我有一个 dask dataframe ,其中出现了一些inf值。 I wish to areplace these on a per column basis, because where inf exists I can replace with a value that is appropriate to the upper bounds that can be expected from that column.我希望在每列的基础上放置这些,因为在存在 inf 的地方,我可以用适合于该列可以预期的上限的值替换。

I'm having some trouble understandingthe documentation , or rather translating it into something I can use to replace infinite values.我在理解文档时遇到了一些麻烦,或者更确切地说,将其翻译成我可以用来替换无限值的东西。

What I have been trying is roughly around the below, replacing inf with 1000 - however the inf value seems to remain in place, unchanged.我一直在尝试的大致如下,将inf替换为1000 - 但是 inf 值似乎保持不变,没有变化。

Any advice on how to do this would be excellent.关于如何做到这一点的任何建议都会非常好。 Because this is a huge dataframe (10m rows, 40 cols) I'd prefer to do it in a fashion that doesn't use lamba or loops- which the below should basically achieve, but doesn't.因为这是一个巨大的 dataframe(10m 行,40 列),所以我宁愿以一种不使用 Lamba 或循环的方式来完成它——下面基本上应该实现,但没有。

ddf['mycolumn'].replace(np.inf,1000)

Following @Enzo's comment, make sure you are assigning the replaced values back to the original column:在@Enzo 的评论之后,确保将替换的值分配回原始列:

import numpy as np
import pandas as pd
import dask.dataframe as dd

df = pd.DataFrame([1, 2, np.inf], columns=['a'])
ddf = dd.from_pandas(df, npartitions=2)
ddf['a'] = ddf['a'].replace(np.inf, 1000)

# check results with: ddf.compute()
#         a
# 0     1.0
# 1     2.0
# 2  1000.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM