如何重命名Dask数据框的索引 [英] How to rename the index of a Dask Dataframe

查看:79
本文介绍了如何重命名Dask数据框的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何在一个轻快的数据帧上重命名索引?我这样尝试过

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

df.index.name = 'foo'

但是重新检查df.index.name显示它仍然是以前的样子.

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

推荐答案

这似乎不是一种有效的方法,所以如果有更直接的方法,我也不会感到惊讶.

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以'foo'开头;

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

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

d.map_partitions(f, 'pow')

现在输出的索引名称为"pow".如果使用线程调度程序完成此操作,我想您还就地更改了d的索引名(在这种情况下,您实际上并不需要map_partitions的输出).

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).

这篇关于如何重命名Dask数据框的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆