UBC-MDS / NiceNumber

Convert numbers to make them more human or machine readable, depending on the application.
MIT License
1 stars 2 forks source link

NiceNumber

codecov Release Documentation Status

This Python package provides basic functions that make numbers display nicely. In most real-world problems, the datasets are raw and we need to deal with number formats to make them readable for humans or for computers. Usually, a few or more lines of coding are needed while dealing with number-display problems so we are thinking of compressing the time and programming work on this issue. This package solves this kind of problems in a way of transfer forward and backward from long digit numbers to human-readable ones. There are functions doing single number transactions, column transactions from a pandas data frame, and displaying colors of input numbers.

Installation

$ pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple nicenumber

Features

There are four functions in this package:

from nicenumber import nicenumber as nn

n = 1234.5
nn.to_human(n=n, precision=1, family='number')

>>> '1.2K'
from nicenumber import nicenumber as nn

string = '4.51k'
nn.to_numeric(string=string, family='number')

>>> '4510.0'
from nicenumber import nicenumber as nn

df = pd.DataFrame(np.array([[1_000, 1_000_000], [1_000_000_000, 1_000_000_000_000]]), columns=['A', 'B'])

nn.to_pandas(df, columns=['A'], transform_type='human')

>>>
A B
0 1K 1000000
1 1B 1000000000000
from nicenumber import nicenumber as nn

nn.to_color(1234567, ['green', 'red', 'blue'])

1234567

Python Ecosystem

There are several python packages that have similar functionalities with this package in the Python ecosystem. For example:

We aim to optimize those existing packages so that the users can use one package instead of using several packages at the same time.

Documentation

The official documentation is hosted on Read the Docs: https://nicenumber.readthedocs.io/en/latest/

Contributors

We welcome and recognize all contributions. You can see a list of current contributors in the contributors tab.

Credits

This package was created with Cookiecutter and the UBC-MDS/cookiecutter-ubc-mds project template, modified from the pyOpenSci/cookiecutter-pyopensci project template and the audreyr/cookiecutter-pypackage.