[英]Reindexing a pandas DataFrame using a dict (python3)
Is there a way, without use of loops, to reindex a DataFrame
using a dict
? 有没有办法,不使用循环,使用
dict
重新索引DataFrame
? Here is an example: 这是一个例子:
df = pd.DataFrame([[1,2], [3,4]])
dic = {0:'first', 1:'second'}
I want to apply something efficient to df
for obtaining: 我想对
df
应用一些有效的东西来获得:
0 1
first 1 2
second 3 4
Speed is important, as the index in the actual DataFrame
I am dealing with has a huge number of unique values. 速度很重要,因为我正在处理的实际
DataFrame
的索引具有大量的唯一值。 Thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.