.at和.loc在 pandas 中的时间复杂度是多少? [英] What is the time complexity of .at and .loc in pandas?

查看:141
本文介绍了.at和.loc在 pandas 中的时间复杂度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找这些方法的时间复杂度,它是数据帧n中行数的函数.

I'm looking for the time complexity of these methods as a function of the number of rows in a dataframe, n.

问这个问题的另一种方法是:熊猫btree(具有log(n)时间查找)或哈希表(具有恒定时间查找)中的数据帧索引是?

Another way of asking this question is: Are indexes for dataframes in pandas btrees (with log(n) time look ups) or hash tables (with constant time lookups)?

问这个问题,是因为我想基于自定义索引对数据框中的行进行恒定时间查找.

Asking this question because I'd like a way to do constant time look ups for rows in a dataframe based on a custom index.

推荐答案

好的,这样看来:

1)您可以使用.set_index 在O(n)时间中建立自己的索引,其中n是数据帧中的行数

1) You can build your own index on a dataframe with .set_index in O(n) time where n is the number of rows in the dataframe

2)第一次尝试使用该索引访问行时,该索引被延迟初始化和构建(在O(n)时间内).因此,使用该索引首次访问行需要O(n)时间

2) The index is lazily initialized and built (in O(n) time) the first time you try to access a row using that index. So accessing a row for the first time using that index takes O(n) time

3)所有随后的行访问都需要固定的时间.

所以看起来索引是哈希表而不是btree.

So it looks like the indexes are hash tables and not btrees.

这篇关于.at和.loc在 pandas 中的时间复杂度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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