process data as stream.
Project description
从目录读取所有文件,从csv读取所有数据,从mysql读取数据。
对数据按多个函数的组合进行过滤、去重, 对数据列进行转换,对数据进行计算。
对数据进行质量控制(QC)检查,确保最后的数据与预期相符。
将数据写入csv、数据库等。
原理和特点说明
编程主要要到了生成器,各个类用for循环从上游抽取数据,用yield给下游提供数据。通过改写or规则,利用|操作符将各个组建组合起来。
- 特点:
高拓展性。
低内存占用。
丰富的代码注释与样例。
参考项目
整体思路主要参考了这个项目:https://github.com/sandabuliu/python-stream。
安装
>>> pip install file-stream
使用
写数据到数据库。
from file_stream.source import Memory from file_stream.writer import MysqlWriter office_base_config = { 'host': "", 'user': "", 'passwd': '', 'database': '', 'charset': '', } datas = [{'f_cuid': 'id2', 'f_sentence_no': 1, 'f_pos_no': 1, 'f_neg_no': 0, 'f_nu_no': 0}, {'f_cuid': 'id3', 'f_sentence_no': 3, 'f_pos_no': 2, 'f_neg_no': 1, 'f_nu_no': 0}, {'f_cuid': 'id1', 'f_sentence_no': 1, 'f_pos_no': 1, 'f_neg_no': 0, 'f_nu_no': 0}, {'f_cuid': 'id4', 'f_sentence_no': 1, 'f_pos_no': 1, 'f_neg_no': 0, 'f_nu_no': 0}, ] reader = Memory(datas) p = reader | MysqlWriter(office_base_config, 't_report_info') p.output()
从CSV文件读取数据,按条件筛选后输出到屏幕。
reader = CsvReader('/home/hetao/Data/p5w/数据分析/IPO_RoadShow.txt', delimiter='\t', encoding='gbk') fit = Filter(lambda x: True) writer = ScreenOutput(end='\r') p = reader | fit | writer p.output()
更多范例参见test文件夹。
TODO
加入和完善统计模块。
加入和完善QA模块。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for file_stream-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56ea1725a883f4a30c0383b452e396fa20450f4dc0f164e449c543a5a2b7b21f |
|
MD5 | fc23558be28aa46817e3d006823da7d2 |
|
BLAKE2b-256 | 6d6e393e13294fcd1d61cfb0da8534c0707f5cc938997e548fc2c927ac06c429 |