Module to parse a number-string to a float or decimal.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file finparse-0.1.4.tar.gz.
File metadata
- Download URL: finparse-0.1.4.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9584ad0b0b724c0c077f9d0533e132d9bc4b9255d61df43f4df570206ae4865
|
|
| MD5 |
00dc12d910d4f515cea3829cea92f4b4
|
|
| BLAKE2b-256 |
46ffff4a9c282b71320dd337234399be7c9da14aa76ed3f01a961f97f2b3c9fd
|
File details
Details for the file finparse-0.1.4-py3-none-any.whl.
File metadata
- Download URL: finparse-0.1.4-py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e107217fba9c24ef4e0853cfd855339672561b80577296ed1e76f0c81d61d3f
|
|
| MD5 |
f929b9b0f40f05283d912ef1c5793ba0
|
|
| BLAKE2b-256 |
83288dfb3b3832b70a3620529d18137df70cd6cf70bddee3881f7a3ac951bf05
|