Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amancevice/finparse
Parse financial strings to number objects
https://github.com/amancevice/finparse
finance python
Last synced: 13 days ago
JSON representation
Parse financial strings to number objects
- Host: GitHub
- URL: https://github.com/amancevice/finparse
- Owner: amancevice
- License: mit
- Created: 2016-11-10T19:52:14.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2024-03-10T15:22:48.000Z (8 months ago)
- Last Synced: 2024-10-10T04:07:54.959Z (about 1 month ago)
- Topics: finance, python
- Language: Python
- Size: 74.2 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Finparse
![pypi](https://img.shields.io/pypi/v/finparse?color=yellow&logo=python&logoColor=eee&style=flat-square)
![python](https://img.shields.io/pypi/pyversions/finparse?logo=python&logoColor=eee&style=flat-square)
[![pytest](https://img.shields.io/github/workflow/status/amancevice/finparse/pytest?logo=github&style=flat-square)](https://github.com/amancevice/finparse/actions)
[![coverage](https://img.shields.io/codeclimate/coverage/amancevice/finparse?logo=code-climate&style=flat-square)](https://codeclimate.com/github/amancevice/finparse/test_coverage)
[![maintainability](https://img.shields.io/codeclimate/maintainability/amancevice/finparse?logo=code-climate&style=flat-square)](https://codeclimate.com/github/amancevice/finparse/maintainability)Parse financial strings to number objects
## Installation
```bash
pip install finparse
```## Usage
```python
import finparsefinparse.parse("$1,234,567.89")
# => 1234567.89finparse.parse("€1.234.567,89", decimal=",")
# => 1234567.89finparse.parse("($1,234,567.89)")
# => -1234567.89import decimal
finparse.parse("$1,234,567.89", cast=decimal.Decimal)
# => Decimal('1234567.89')
```## Pandas
Pandas' `read_csv()` function provdides a `converters` argument that applies a function to the given column.
Using the example CSV file [`./tests/example.csv`](./tests/example), we can see the following behavior:
```python
import pandasdf = pandas.read_csv('./tests/example.csv')
print(df)
# => Acct Balance
# 0 Savings $1,234.567
# 1 Checking ($0.987)
```With the `converters` argument we can parse these values to floats:
```python
import finparse
import pandasdf = pandas.read_csv('./tests/example.csv', converters={'Balance': finparse.parse})
print(df)
# => Acct Balance
# 0 Savings 1234.567
# 1 Checking -0.987
```