Pandas Apply函数
来源:互联网 发布:tomcat修改1099端口 编辑:程序博客网 时间:2024/06/05 15:15
Series.apply
Series.apply(func, convert_dtype=True, args=(), **kwds)
对序列的每一个元素作用传入的函数
参数
返回
- y : Series or DataFrame if func returns a Series
DataFrame.apply
DataFrame.apply(func, axis=0, broadcast=False, raw=False, reduce=None, args=(), **kwds)
在给定轴方向应用函数
参数
func : function|要应用在行和列的函数
axis : {0 or ‘index’, 1 or ‘columns’}, default 0|选择是行还是列
broadcast : boolean, default False|For aggregation functions, return object of same size with values propagated
raw : boolean, default False|If False, convert each row or column into a Series. If raw=True the passed function will receive ndarray objects instead.
reduce : boolean or None, default None|Try to apply reduction procedures.
args : tuple|函数的参数
应用
查看序列中元素的类型
In [1]: import pandas as pd ...: df=pd.Series(["1","a",1,True]) ...: dfOut[1]: 0 11 a2 13 Truedtype: objectIn [2]: df.apply(type)# 这里使用type()函数Out[2]: 0 <class 'str'>1 <class 'str'>2 <class 'int'>3 <class 'bool'>dtype: objectIn [3]: %timeit df.apply(type) #每次循环的时间是101us10000 loops, best of 3: 101 µs per loop
apply函数类似与如下的循环
In [4]: [type(x) for x in df]Out[4]: [str, str, int, bool]In [5]: %timeit [type(x) for x in df]100000 loops, best of 3: 13.3 µs per loop
很奇怪,循环要比pandas的内置函数要快
阅读全文
0 0
- Pandas 的apply函数
- Pandas Apply函数
- pandas apply函数的入门
- 【Python】Pandas的apply函数使用示例
- pandas apply 函数 多进程实现
- pandas中apply函数的用法
- pandas函数应用篇之GroupBy.apply
- 【Python】Pandas——apply函数
- pandas中apply函数的用法
- Python】Pandas的apply函数使用示例
- pandas 中有关agg函数和apply函数的区别
- Pandas groupby apply agg 区别 运行自定义函数
- pandas apply value_counts
- pandas中apply筛选数据
- 理解pandas的groupby().apply()
- pandas中apply的使用方法
- pandas的apply和map、applymap
- pandas apply vs agg vs transform
- caffe(一): 利用自带MNIST例程训练手写字符识别模型
- epoll服务器---I/O多路转接之epoll
- JSON.parse()和JSON.stringify()
- linux ./config --prefix=
- LeetCode2:Add Two Numbers
- Pandas Apply函数
- ubuntu linux基本命令- 改变工作目录命令
- 开通新博客了
- 名企笔试:Amazon笔试题(Count the elements)
- 学习博客园开源代码笔记(一)
- clone()的使用
- this web application instance has been stopped already. Could not load net.sf.ehcache.store.compoun
- c++构造函数的初始化列表
- tensorflow.layers.batch_normalization使用方法