Skip to main content

pyaxe-pandas

对pandas进行配置文件操作,用yml文件对pandas进行操作,无须写一行代码即可分析数据。

安装

pip install pyaxe-pandas

执行

from pyaxe_pandas import YamlPandas
import pandas as pd
df=pd.DataFrame()

yp = YamlPandas(df=df, yml='yaml配置文件地址')
result = yp.resolve_config(yp.read_yaml())
for data in result:
    print(data)

语法文档

语法文档

生成初始化数据

import pandas as pd
import random

random.seed(100)
df=pd.DataFrame({'age':[random.randint(10,100) for i in range(2000)],'sex':['男' if random.randint(10,100)%2==0 else '女' for i in range(2000)]})
'''
age	sex
0	28	女
1	68	女
2	68	女
3	32	女
4	100	男
...	...	...
1995	14	女
1996	33	女
1997	23	男
1998	92	女
1999	76	女
2000 rows × 2 columns
'''

一系列过滤操作

# df
#   age	sex
#0	28	女
#1	68	女
#2	68	女
#3	32	女
#4	100	男
#...	...	...
#1995	14	女
#1996	33	女
#1997	23	男
#1998	92	女
#1999	76	女
#2000 rows × 2 columns

# 1、 大于50岁的人
version: 1.1.0
operations:
  - operation:
      name: query
      exe: age > 60 and sex =="男"
---

# 2、 大于60岁的男人
version: 1.1.0
operations:
  - operation:
      name: query
      exe: age > 60 and sex =="男"
---

# 3、 大于30岁的男人或者小于70岁的女人
version: 1.1.0
operations:
  - operation:
      name: query
      exe: (age > 60 and sex =="男") or (age < 70 and sex=="女")
---

# 4、 大于平均年龄的女人
version: 1.1.0
operations:
  - operation:
      name: query
      exe: age > age.mean() and sex =="女"

条件过滤

version: 1.1.0
operations:
  - operation:
      name: query
      switch:
        - regex: 大于50岁 # 大于50岁的人
          arg: text # 匹配的参数
          exe: age > 50
          stop: true

        - regex: 大于60岁.+男 # 大于60岁的男人
          arg: text
          exe: age > 60 and sex =="男"
          stop: true

        - regex: .+30岁的男人或者小于70岁的女人 # 大于30岁的男人或者小于70岁的女人
          arg: text
          exe: (age > 60 and sex =="男") or (age < 70 and sex=="女")
          stop: true

        - regex: 平均年龄.+女人 # 大于平均年龄的女人
          arg: text
          exe: age > age.mean() and sex =="女"
          stop: true

Release files for pyaxe-pandas 2020.8.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for pyaxe-pandas 2020.8.18
File Interpreter ABI Platform
pyaxe_pandas-2020.8.18-py3-none-any.whl Python 3 none any Details

Release files / pyaxe_pandas-2020.8.18-py3-none-any.whl

Download URL pyaxe_pandas-2020.8.18-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fb16890a56095ccc125be132de9534c75ae4ede889837e0db56bb28969016dd4
BLAKE2b-256 checksum
How to use checksums
8d5c67a1d0f1d4fb6b9b1699cdacbc098a407065a795920f0f7ec16ac73ebbf4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

Release history Release notifications | RSS feed

This release

2020.8.18 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page