Parse financial strings to numbers
Project description
Finparse
Parse financial strings to number objects
Installation
pip install finparse
Usage
import finparse
finparse.parse("$1,234,567.89")
# => 1234567.89
finparse.parse("€1.234.567,89", decimal=",")
# => 1234567.89
finparse.parse("($1,234,567.89)")
# => -1234567.89
import 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, we can see the following behavior:
import pandas
df = 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:
import finparse
import pandas
df = pandas.read_csv('./tests/example.csv', converters={'Balance': finparse.parse})
print(df)
# => Acct Balance
# 0 Savings 1234.567
# 1 Checking -0.987
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
finparse-0.1.2.tar.gz
(5.3 kB
view details)
File details
Details for the file finparse-0.1.2.tar.gz.
File metadata
- Download URL: finparse-0.1.2.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d51e6e04959a459a38361f6a17eb4bcb1dcf865ab1a968b05efb063683fdffe2
|
|
| MD5 |
779b610b1a36e0bcd9b4272cca6cf417
|
|
| BLAKE2b-256 |
b1ea7fa0512c9ea58bdfaef0950444c6fa4aa8f36d46dc567f2333c2bfbdf058
|