![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
文章平均质量分 55
BlueWhale52
We are like a 52Hz blue whale, unique.
And hope the ending is like a whale falling.
展开
-
Python的bisect模块——数组二分查找算法
bisect 模块bisect 模块实现了对有序数组的二分查找和插入,使用该模块插入数据时仍能保持有序。bisect 模块源码bisect 的源码短小精悍,也可以作为二分查找算法的示例。整个模块去掉注释,就以下这么多代码。"""Bisection algorithms."""def insort_right(a, x, lo=0, hi=None): lo = bisect_right(a, x, lo, hi) a.insert(lo, x)def bisect_rig原创 2021-08-19 16:52:25 · 663 阅读 · 0 评论 -
Python读取大文件
当我们使用 read() 或 readlines() 读取文件时,会直接把全部内容读取到内存中。但当文件非常大,甚至超过了电脑自身的内存大小,就无法使用这些方法处理了。我们可以使用 把文件 f 作为迭代对象及使用 with 来进行处理。with open('bigText.txt', 'r', encoding='utf-8') as f: for line in f: print(line) # do something...其具有以下优点:在退出 with 执行块后,原创 2021-08-11 17:37:25 · 167 阅读 · 0 评论 -
对Dataframe进行多列排序——sort_values
sort_values() 函数说明pandas库的 sort_values() 函数可以对 Dataframe 的数据集按照某个字段中的数据进行排序。该函数可以指定列数据或行数据进行排序,可以是单个,也可以是多个。同时,对于 series 也有 sort_values() 函数,但在参数上稍有区别。官方介绍:pandas.DataFrame.sort_valuespandas.Series.sort_valuessort_values() 具体参数用法: DataFrame.sort_v原创 2021-07-28 18:45:43 · 17892 阅读 · 0 评论