假设这是一个数据帧(df)中的4行,其中有许多行。在
a b
AB01 1 5
DE44 2 6
GH33 3 7
JK05 4 8
我的目标是更改索引标签。
具体来说,我想把DE44改成DE55,把GH33改成QVXYZ。在
这是有效的:
^{pr2}$
但我作弊了。我知道DE55和GH33标签在行上
测向仪[1] 以及测向仪[2] 这个非常小的样本。在
如果数据帧有很多行,但我不知道标签在哪一行
我想改变,我该怎么做?有没有一种方法可以在不逐行显式迭代的情况下从标签中获取索引整数?在
Tags:
您可以使用字典来高效地替换索引标签,而无需事先知道标签在数据帧的哪一行。诀窍是首先交换行和列。在
一般做法是
示例:
^{pr2}$假设我们有下面的数据帧,并希望更改索引标签A、B和G
用要更改的标签创建词典。
字典的名称-值对的结构如下
以下代码行将上述3个步骤与
按照oldNewRowXref字典中的规定更改索引标签:
考虑到这一点:
退货
^{pr2}$怎么样:
相关问题 更多 >
编程相关推荐