## The pandas ml common module
This module holds all common extensions and utilities for the pandas ml quant stack.
Feel free to study the [examples][ghl1] as well.
* easy joining of data frames with multi indexes
```python
from pandas_ml_common import pd, np
df1 = pd.DataFrame({"a": np.random.random(10), "b": np.random.random(10)})
print(df1.inner_join(df1, prefix_left='A', prefix='B', force_multi_index=True).to_markdown())
```
| | ('A', 'a') | ('A', 'b') | ('B', 'a') | ('B', 'b') |
|---:|-------------:|-------------:|-------------:|-------------:|
| 0 | 0.907892 | 0.726913 | 0.907892 | 0.726913 |
| 1 | 0.602275 | 0.134278 | 0.602275 | 0.134278 |
| 2 | 0.264399 | 0.207429 | 0.264399 | 0.207429 |
| 3 | 0.559751 | 0.816759 | 0.559751 | 0.816759 |
| 4 | 0.951172 | 0.797524 | 0.951172 | 0.797524 |
| 5 | 0.504332 | 0.51996 | 0.504332 | 0.51996 |
| 6 | 0.765235 | 0.17908 | 0.765235 | 0.17908 |
| 7 | 0.388691 | 0.644103 | 0.388691 | 0.644103 |
| 8 | 0.663636 | 0.678879 | 0.663636 | 0.678879 |
| 9 | 0.291603 | 0.0164627 | 0.291603 | 0.0164627 |
* access columns with regex
```python
df4 = pd.DataFrame({"a_22_a": np.random.random(1), "b_21_b": np.random.random(1)})
df4._[r'.*\d+_.']
```
| | a_22_a | b_21_b |
|---:|---------:|----------:|
| 0 | 0.22039 | 0.0374084 |
* easy access multi level index
```python
df1.unique_level_columns(0)
['A', 'B']
df1.add_multi_index('Z', axis=1)
```
* data splitting, sampling and folding (aka cross validation)
```python
from pandas_ml_common import Sampler, XYWeight, random_splitter
df2 = pd.DataFrame({"c": np.random.random(10)})
sampler = Sampler(XYWeight(df1, df2), splitter=random_splitter(0.5))
for batches in sampler.sample_for_training():
for batch in batches:
print(batch)
```
* access to nested numpy arrays in data frame columns (`df._.values`)
```python
df3 = pd.DataFrame({"a": [[1, 2], [3, 4], [5, 6]]})
df3._.values
array([[1, 2],
[3, 4],
[5, 6]])
```
* dynamic method call providing suitable *args and **kwargs (dependency injection)
```python
from pandas_ml_common import call_callable_dynamic_args
def adder(a, b):
return a + b
call_callable_dynamic_args(adder, a=12, b=10, c='illegal')
22
```
* numpy utils
```python
from pandas_ml_common import np_nans
np_nans((3, 3))
array([[nan, nan, nan],
[nan, nan, nan],
[nan, nan, nan]])
from pandas_ml_common import temp_seed
with temp_seed(42):
print(np.random.random(2))
np.random.random(2)
[0.37454012 0.95071431]
array([0.69373278, 0.69790163])
```
* serialization utils
```python
from pandas_ml_common import serializeb, deserializeb
deserializeb(serializeb(np.array([1, 2, 3])))
array([1, 2, 3])
```
* re-scalings
```python
from pandas_ml_common import ReScaler
x = np.arange(0, 1, .1)
rescaler = ReScaler((0, 1), (5, -5))
rescaler(x)
array([ 5., 4., 3., 2., 1., 0., -1., -2., -3., -4.])
```
[ghl1]: https://github.com/KIC/pandas-ml-quant/tree/0.2.7/pandas-ml-common/./examples/
没有合适的资源?快使用搜索试试~ 我知道了~
pandas-ml-common-0.2.7.tar.gz
需积分: 1 0 下载量 56 浏览量
2024-03-07
12:42:29
上传
评论
收藏 246KB GZ 举报
温馨提示
共170个文件
pyc:103个
py:52个
txt:9个
Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
资源推荐
资源详情
资源评论
收起资源包目录
pandas-ml-common-0.2.7.tar.gz (170个子文件)
setup.cfg 79B
SPY.csv 488KB
MANIFEST.in 88B
Readme.md 3KB
PKG-INFO 5KB
PKG-INFO 5KB
sampler.py 10KB
callable_utils.py 8KB
index_utils.py 8KB
value_utils.py 7KB
test__sampler.py 6KB
test__value_utils.py 6KB
test__training_test_data_split.py 5KB
splitter.py 4KB
cross_validation.py 4KB
test__index_utils.py 3KB
numpy_utils.py 3KB
test__ml_values.py 3KB
multi_frame_decorator.py 3KB
df_values.py 3KB
test__ml_items.py 3KB
setup.py 2KB
__init__.py 2KB
serialization_utils.py 2KB
test__callable_utils.py 2KB
test__value_lagging.py 2KB
test__multi_frame_decorator.py 2KB
test__cross_validation.py 2KB
jupyther_utils.py 2KB
column_lagging_utils.py 2KB
noxfile.py 2KB
notebook_runner.py 1KB
link_checker.py 1KB
normalization.py 1KB
test_numpy.py 1KB
time_utils.py 1KB
config.py 809B
test__lazy_init.py 760B
lazy_value.py 654B
logging_utils.py 480B
random.py 429B
test__serialization_utils.py 421B
__init__.py 414B
test_random.py 380B
test_notebooks.py 356B
test__ml.py 303B
test__ml_extract.py 270B
__init__.py 217B
check_links.py 173B
types.py 156B
__init__.py 54B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
test__sampler.cpython-38.pyc 8KB
test__sampler.cpython-37-pytest-6.1.0.pyc 8KB
test__sampler.cpython-37.pyc 8KB
sampler.cpython-38.pyc 8KB
sampler.cpython-37.pyc 7KB
index_utils.cpython-38.pyc 7KB
test__value_utils.cpython-38.pyc 7KB
test__value_utils.cpython-37-pytest-6.1.0.pyc 7KB
test__value_utils.cpython-37.pyc 7KB
index_utils.cpython-37.pyc 7KB
multi_frame_decorator.cpython-37.pyc 6KB
multi_frame_decorator.cpython-38.pyc 6KB
value_utils.cpython-38.pyc 6KB
value_utils.cpython-37.pyc 6KB
callable_utils.cpython-38.pyc 5KB
callable_utils.cpython-37.pyc 5KB
test__training_test_data_split.cpython-37.pyc 5KB
test__training_test_data_split.cpython-38.pyc 4KB
cross_validation.cpython-38.pyc 4KB
splitter.cpython-38.pyc 4KB
splitter.cpython-37.pyc 4KB
cross_validation.cpython-37.pyc 4KB
numpy_utils.cpython-38.pyc 4KB
numpy_utils.cpython-37.pyc 4KB
test__callable_utils.cpython-37-pytest-6.1.0.pyc 4KB
test__index_utils.cpython-38.pyc 4KB
test__callable_utils.cpython-37.pyc 4KB
test__callable_utils.cpython-38.pyc 4KB
df_values.cpython-38.pyc 3KB
test__ml_values.cpython-37-pytest-6.1.0.pyc 3KB
test__ml_values.cpython-37.pyc 3KB
test__ml_values.cpython-38.pyc 3KB
test__ml_items.cpython-37-pytest-6.1.0.pyc 3KB
__init__.cpython-38.pyc 3KB
serialization_utils.cpython-38.pyc 3KB
__init__.cpython-37.pyc 3KB
test__ml_items.cpython-37.pyc 3KB
test__ml_items.cpython-38.pyc 3KB
df_values.cpython-37.pyc 3KB
test__training_test_data_split.cpython-37-pytest-6.1.0.pyc 2KB
serialization_utils.cpython-37.pyc 2KB
test__multi_frame_decorator.cpython-38.pyc 2KB
共 170 条
- 1
- 2
资源评论
程序员Chino的日记
- 粉丝: 3035
- 资源: 4万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功