赞
踩
怎样解决python dataframe loc,iloc循环处理速度很慢的问题
1.问题说明
最近用DataFrame做大数据 处理,发现处理速度特别慢,追究原因,发现是循环处理时,loc,iloc速度都特别慢,当数据量特别大得时候真的是超级慢。查很多资料,发现没有详细说明,以下为解决办法
2.问题解决
使用 Pandas.Series.apply 方法,可以对一列数据快速进行处理
Series.apply(*func*, *convert_dtype=True*, *args=()*, **\*kwds*)
函数说明:
To lunch typora from Terminal, you could add
func : function
convert_dtype : boolean, default True
Try to find better dtype for elementwise function results. If False, leave as dtype=object
args : tuple
Positional arguments to pass to function in addition to the value
Additional keyword arguments will be passed as keywords to the function
例子讲解
# 首先导入数据
>>> import pandas as pd
>>> import numpy as np
>>> series = pd.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。