Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename the index of a Dask Dataframe

How would I go about renaming the index on a dask dataframe? I tried it like so

df.index.name = 'foo'

but rechecking df.index.name shows it still being whatever it was previously.

like image 626
Samantha Hughes Avatar asked Jun 02 '17 21:06

Samantha Hughes


1 Answers

This does not seem like an efficient way to do it, so I wouldn't be surprised if there is something more direct.

d.index.name starts off as 'foo';

def f(df, name):
    df.index.name = name
    return df

d.map_partitions(f, 'pow')

The output now has index name of 'pow'. If this is done with the threaded scheduler, I think you also change the index name of d in-place (in which case you don't really need the output of map_partitions).

like image 95
mdurant Avatar answered Sep 30 '22 19:09

mdurant