Martins Python Utilities
项目描述
mpu
Martins Python Utilities (mpu) 是一个无其他依赖的实用函数和类别的集合。
该包的总大小永远不会超过 10 MB,目前以压缩形式为 15.7 kB。这使得它适合包含在 AWS Lambda 项目中。
安装
$ pip install git+https://github.com/MartinThoma/mpu.git
当然,也可以通过 PyPI 进行安装。
用法
数据结构
>>> from mpu.datastructures import EList
>>> l = EList([2, 1, 0])
>>> l[2]
0
>>> l[[2, 0]]
[0, 2]
>>> l[l]
[0, 1, 2]
Shell
为了增强您的终端输出,您可能想要做一些类似以下的事情
from mpu.shell import Codes
print("{c.GREEN}{c.UNDERLINED}Works{c.RESET_ALL}".format(c=Codes))
快速示例
创建小型示例数据结构是我偶尔在 StackExchange 答案中遇到的任务。
from mpu.pd import example_df
df = example_df()
print(df)
给出
country population population_time EUR
0 Germany 82521653.0 2016-12-01 True
1 France 66991000.0 2017-01-01 True
2 Indonesia 255461700.0 2017-01-01 False
3 Ireland 4761865.0 NaT True
4 Spain 46549045.0 2017-06-01 True
5 Vatican NaN NaT True
货币
import mpu
from fractions import Fraction
gross_income = mpu.units.Money("2345.10", "EUR")
net_income = gross_income * Fraction("0.80")
apartment = mpu.units.Money("501.23", "EUR")
savings = net_income - apartment
print(savings)
打印 1375.31 欧元
IO
- 使用
mpu.io.download(source, sink)
下载文件 - 使用
mpu.io.read(filepath)
读取 CSV、JSON 和 pickle - 使用
mpu.io.write(filepath, data)
写入 CSV、JSON 和 pickle
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源代码分发
mpu-0.23.1.tar.gz (65.4 kB 查看哈希值)
构建分发
mpu-0.23.1-py3-none-any.whl (69.7 kB 查看哈希值)