How to rename the index of a Dask Dataframe

2024/10/12 7:22:38

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.

Answer

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 = namereturn dfd.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).

https://en.xdnf.cn/q/69678.html

Related Q&A

Determine if a line segment intersects a polygon

If I have a vector (a line consisting of 2 points) on a 2D plane how can I determine if it has passed through a polygon? I know I can take each line which makes up the polygon and see if any intersect…

How to send a value from Arduino to Python and then use that value

I am in the process of building a robot that is remote controlled using Python to send control messages via the Internet through a simple GUI.I have gotten part of my code working pretty well, the GUI …

recaptcha wasnt solving by anticaptcha plugin in selenium python

Ive recently started using selenium for a project Ive been working on for a while that involves automation. One of the roadblocks in the plan was the ReCaptcha system, so I decided to use anti-captcha …

Python - check for class existance

Is there a way to check if a class has been defined/exists? I have different options on a menu, and some of them require inherited variables, so if you try to select that function before you have set …

getting a matplotlib colorbar tick outside data limits for use with boundaries keyword

I am trying to use a colorbar to label discrete, coded values plotted using imshow. I can achieve the colorbar that I want using the boundaries and values keywords, which makes the maximum value of the…

Apache Airflow - customize logging format

Is it possible to customize the format that Airflow uses for logging?I tried adding a LOG_FORMAT variable in $AIRFLOW_HOME/airflow.cfg, but it doesnt seem to take effectLOG_FORMAT = "%(asctime)s …

How can I set up Celery to call a custom worker initialization?

I am quite new to Celery and I have been trying to setup a project with 2 separate queues (one to calculate and the other to execute). So far, so good. My problem is that the workers in the execute que…

Why does print(__name__) give builtins?

Im using pycharm.2017.1.2. I installed anaconda2 with py3 environment. in Pycharm, Im using Python3 interpreter, and the code is simply:print(__name__)In Python console in Pycharm, it prints builtins.I…

List Comprehensions and Conditions?

I am trying to see if I can make this code better using list comprehensions. Lets say that I have the following lists:a_list = [HELLO,FOO,FO1BAR,ROOBAR,SHOEBAR]regex_list = [lambda x: re.search(rFOO,…

Python in operator time complexity on range()

I have the following function:def foo(length, num):return num in range(length)Whats the time complexity of this function? Noting that range() creates a Range object on Python 3, will the time complexi…