数据处理的函数式编程工具
fntools的Python项目详细描述
target: | https://readthedocs.org/projects/fntools/?badge=master |
---|---|
alt: | Documentation Status |
fntools提供用于数据处理的函数式编程工具。这个 模块是我在工作中需要并发现有用的一组函数。
安装
pip install fntools
示例
使用split拆分元素列表:
songs = ('Black', 'Even Flow', 'Amongst the waves', 'Sirens') albums = ('Ten', 'Ten', 'Backspacer', 'Lightning Bolt') print split(songs, albums) {'Lightning Bolt': ['Sirens'], 'Ten': ['Black', 'Even Flow'], 'Backspacer': ['Amongst the waves']}
确定列表中的任何元素是否包含在另一个列表中,其中any_in:
print any_in(['Oceans', 'Big Wave'], ['Once', 'Alive', 'Oceans', 'Release']) True print any_in(['Better Man'], ['Man of the Hour', 'Thumbing my way']) False
使用dispatch对数据应用许多函数:
# Suppose we want to know the mean, the standard deviation and the median of # a distribution (here we use the standard normal distribution) import numpy as np np.random.seed(10) x = np.random.randn(10000) print dispatch(x, (np.mean, np.std, np.median)) [0.0051020560019149385, 0.98966401277169491, 0.013111308495186252]
更多有用的功能是可用的。有关详细信息,请转到 documentation。
灵感
- 优秀的toolz作者Matthew Rocklin
- A pratical introduction to functional programming按Mary Rose Cook
- 一点R(多重映射,使用,与一起使用)