Dask equivalent to Pandas replace?

大城市里の小女人 提交于 2019-11-30 15:02:14

You can use mask:

df = df.mask(df == 'PASS', '0')
df = df.mask(df == 'FAIL', '1')

Or equivalently chaining the mask calls:

df = df.mask(df == 'PASS', '0').mask(df == 'FAIL', '1')

If anyone would like to know how to replace certain values in a specific column, here's how to do this:

def replace(x: pd.DataFrame) -> pd.DataFrame:
    return x.replace(
      {'a_feature': ['PASS', 'FAIL']},
      {'a_feature': ['0', '1']}
    )
df = df.map_partitions(replace)

Since we operate on a pandas' DataFrame here, please refer to the documentation for further information

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!