[Python] Renaming columns in dask dataframe

Discussão em 'Python' iniciado por Stack, Junho 10, 2025.

  1. Stack

    Stack Membro Participativo

    I have two questions about dask. First: The documentation for dask clearly states that you can rename columns with the same syntax as pandas. I am using dask 1.0.0. Any reason why I am getting these errors below?

    df = pd.DataFrame(dictionary)
    df


    [​IMG]

    # I am not sure how to choose values for divisions, meta, and name. I am also pretty unsure about what these really do.
    ddf = dd.DataFrame(dictionary, divisions=[8], meta=pd.DataFrame(dictionary), name='ddf')
    ddf


    [​IMG]

    cols = {'Key':'key', '0':'Datetime','1':'col1','2':'col2','3':'col3','4':'col4','5':'col5'}

    ddf.rename(columns=cols, inplace=True)

    TypeError: rename() got an unexpected keyword argument 'inplace'


    Ok so i removed the inplace=True and tried this:

    ddf = ddf.rename(columns=cols)

    ValueError: dictionary update sequence element #0 has length 6; 2 is required


    The pandas dataframe is showing a real dataframe, but when I call ddf.compute() I get an empty dataframe.

    [​IMG]

    My second question is that I am slightly confused about how to assign divisions, meta, and name. How is this useful/hurtful if I use dask to parallelize on a single machine vs a cluster?

    Continue reading...

Compartilhe esta Página