-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
147 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,33 @@ | ||
# Moneypandas | ||
|
||
Moneypandas is a prototype fork of Cyberpandas for currency, using the `money` library. | ||
Moneypandas is a prototype fork of Cyberpandas for currency, using the `money` library. Even this README is shamelessly purloigned, with thanks to Tom Augspurger and the ContinuumIO team. | ||
|
||
---- | ||
|
||
# Cyberpandas | ||
|
||
[![Build Status](https://travis-ci.org/ContinuumIO/cyberpandas.svg?branch=master)](https://travis-ci.org/ContinuumIO/cyberpandas) | ||
[![Documentation Status](https://readthedocs.org/projects/cyberpandas/badge/?version=latest)](http://cyberpandas.readthedocs.io/en/latest/?badge=latest) | ||
|
||
Cyberpandas provides support for storing IP and MAC address data inside a pandas DataFrame using pandas' [Extension Array Interface](http://pandas-docs.github.io/pandas-docs-travis/extending.html#extension-types) | ||
This package provides support for storing currency data inside a pandas DataFrame using pandas' [Extension Array Interface](http://pandas-docs.github.io/pandas-docs-travis/extending.html#extension-types) | ||
|
||
```python | ||
In [1]: from cyberpandas import IPArray | ||
In [1]: from moneypandas import MoneyArray | ||
|
||
In [2]: import pandas as pd | ||
|
||
In [3]: df = pd.DataFrame({"address": IPArray(['192.168.1.1', '192.168.1.10'])}) | ||
In [3]: df = pd.DataFrame({"money": MoneyArray(['1284 EUR', '121 EUR', '€14'])}) | ||
|
||
In [4]: df | ||
Out[4]: | ||
address | ||
0 192.168.1.1 | ||
1 192.168.1.10 | ||
money | ||
0 EUR 1,284.00 | ||
1 EUR 121.00 | ||
2 EUR 14.00 | ||
``` | ||
|
||
See the [documentation](https://cyberpandas.readthedocs.io/en/latest/) for more. | ||
|
||
## Installation | ||
|
||
With Conda: | ||
For more examples, including summing and converting mixed-currency columns, see the `examples` folder. | ||
|
||
conda install -c conda-forge cyberpandas | ||
(note: not yet tested with Conda, only setuptools/pipenv) | ||
|
||
Or from PyPI | ||
To efficiently perform operations, aggregation is done per currency first, and then XMoney used to do necessary operations on the output aggregates. | ||
|
||
pip install cyberpandas | ||
Currency conversion of a Series only uses XMoney and conversion where currencies mismatch, so converting a column mostly of BBBs, with a few AAAs, should scale according to the number of AAAs. | ||
|
||
## TODO | ||
|
||
* implement more reduce functions | ||
* testing for arithmetic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from moneypandas import MoneyArray | ||
from money import xrates | ||
import decimal | ||
import pandas as pd | ||
|
||
|
||
xrates.install('money.exchange.SimpleBackend') | ||
xrates.base = 'USD' | ||
xrates.setrate('EUR', decimal.Decimal('0.9')) | ||
xrates.setrate('GBP', decimal.Decimal('0.8')) | ||
|
||
df = pd.DataFrame({"money": MoneyArray(['1284 EUR', '121 EUR', '€14', '£12'], 'USD')}) | ||
total = df['money'].sum() | ||
print("Total: ", total) | ||
print("Total (EUR): ", total.to('EUR')) | ||
|
||
df['money'] = df['money'].money.to_currency('EUR') | ||
mean = df['money'].mean() | ||
print("Mean: ", mean) | ||
|
||
df['money'].money.to_currency('GBP', shallow=False, in_place=True) | ||
print('All converted to GBP', df) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters