0

I have a huge database, which I need to change the value of a column according to a certain condition.

In Pandas I execute the following code to accomplish what I want:

df.loc[
        (df['ID_CRITERIO_APURACAO'] == TipoDestinatario.RESIDENCIAL.value) &
        (df['CODG_GRUPO_TENSAO'] == 8) &
        (df['CONSUMO'].between(0, 30)),
        'DESCONTO'
    ] = 35

How can I do something similar in Dask?

Nick ODell
  • 15,465
  • 3
  • 32
  • 66
  • Dask usually works exactly the same way than pandas. Have you tried your code with a Dask dataframe? – Juan C Aug 08 '19 at 14:31
  • Yes, I tried, but it didn't work. Returns the following error: TypeError: '_LocIndexer' does not support item assignment – Thiago Carvalho Aug 08 '19 at 14:56

1 Answers1

0

Dask doesn't support inplace mutation. Try this:

condition = (df['ID_CRITERIO_APURACAO'] == TipoDestinatario.RESIDENCIAL.value) &
    (df['CODG_GRUPO_TENSAO'] == 8) &
    (df['CONSUMO'].between(0, 30))

desconto = df.where(condition, 35)
df['DESCONTO'] = desconto
Juan C
  • 5,846
  • 2
  • 17
  • 51
  • Unfortunately it did not work. TypeError: Column assignment doesn't support type dask.dataframe.core.DataFrame – Thiago Carvalho Aug 08 '19 at 16:01
  • What kind of DataFrame is `TipoDestinatario` ? – Juan C Aug 08 '19 at 16:05
  • It seems you can't create columns on `dask`. Try what I edited now. Tell me if at least the `dd.Series` "desconto" is created – Juan C Aug 08 '19 at 16:07
  • TipoDestinatario is an enum. It did not work, the same error occurred: `TypeError: Column assignment doesn't support type dask.dataframe.core.DataFrame.` Even trying to change a column already created, the same perssite error. – Thiago Carvalho Aug 08 '19 at 16:14