hhammond / prettypandas Goto Github PK
View Code? Open in Web Editor NEWA Pandas Styler class for making beautiful tables
Home Page: http://prettypandas.readthedocs.org/
License: MIT License
A Pandas Styler class for making beautiful tables
Home Page: http://prettypandas.readthedocs.org/
License: MIT License
Hello,
https://github.com/HHammond/PrettyPandas/blob/master/Readme.md provides an example
but it should simply be copy/pastable
import pandas as pd
from pandas.compat import StringIO
dat = """A;B;C;D
10;58.0;0.07156;0.39343
2.51;64.0;1.21872;0.33958
5;56.0;1.38399;0.26289
2.51;47.0;0.45284;1.47185
5;46.0;1.19918;2.08354"""
df = pd.read_csv(StringIO(dat), sep=";")
df
from prettypandas import PrettyPandas
(PrettyPandas(df, precision=0)
.as_percent(subset=['C', 'D'], precision=3)
.as_money(subset='A')
.average()
.total()
)
Kind regards
while running this code:
(
df4
.pipe(PrettyPandas)
.as_currency('USD', subset='Average Value')
.as_percent(subset='Yield')
.total()
.average()
)
I get the error:
TypeError: 'module' object is not callable.
I've successfully pip installed prettypandas
and ran import prettypandas
and import babel
All the documentation uses (PrettyPandas). Is this recognizable in Jupyter Notebooks?
Whoops, I forgot to add the section on number formatting.
To make this work the output from _translate
needs to be formatted into a text table. It shouldn't be too hard to do.
Hello,
Example from https://github.com/HHammond/PrettyPandas/blob/master/Readme.md (see #46 )
doesn't print correctly on Jupyter.
Kind regards
Todo:
This looks awesome. Have you tried submitting a PR to include in Pandas?
Screenshot: https://puu.sh/rPAgQ/e17239be96.png
I have this csv file: crosstab_bug.txt
when I execute the following commands in a notebook the False row of has_no_http is missing
import pandas as pd
from prettypandas import PrettyPandas
df = pd.read_csv('crosstab_bug.txt')
crosstab_df = pd.crosstab(df.has_no_http, df.error, aggfunc='count')
PrettyPandas(crosstab_df)
Pandas also allow for this. See their github closed issue #9658.
I know it's not a big issue, but for someone not coming from numpy background, makes things easier than trying to remember which axis 0 or 1 is.
The following fails:
import prettypandas
With:
ImportError: No module named 'pandas.core.style'
The module appears to have moved to pandas.DataFrame.style
(changelist), AFAIK.
Minor, but it would be nice to update requirements.txt
to reflect that the minimum supported pandas version is at least 0.20
, since this is internally using https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.agg.html which was introduced in 0.20
.
Currently summaries are all-or-nothing. It might be worthwhile to allow summaries to use standard subsetting.
The as_percent() format always display the value without decimals and the precision parameter has no effect at all. I checked the code and realized that:
1/ there are 2 as_percent() in formatters (only 'partial' object is used)
2/ the method as_percent() in class PrettyPandas does not use the precision parameter at all, so I changed the call to partial below the comment: '# TODO: Find good way to implement precision' as:
# TODO: Find good way to implement precision
precision = self.precision if precision is None else precision
add_formatter = partial(self._format_cells,
as_percent,
subset=subset,
format='0.{}%'.format('0' * precision))
maybe there is a better implementation but at least the precision is taken into account now.
Not sure how to implement this, but it would be nice if currency defaulted to the user's local currency.
Pandas has a built-in tohtml function which accepts number formatting. There is currently work on adding number formats to the Pandas Styler class. After that is done then that functionality can probably be deleted from this project.
See pandas-dev/pandas#11692 for details on that issue.
Hey Henry,
I'm experiencing the following error:
AttributeError: 'PrettyPandas' object has no attribute 'to_excel'
I also tried to shove the results in a list, and spit the list back out as a dataframe, but that totally failed as well. Would you be able to implement the to_excel function any time soon?
Thank you so much!!!!
Sparklines are a great way to represent data. Edward Tufte has a great post on the theory and applications.
I think sparklines definitely belong in reporting, the question is whether or not PrettyPandas should implement them itself.
What would a sparkline API even look like? Would this use another python library (that seems ideal)?
I'd love the look of http://metricsgraphicsjs.org/examples.htm#lines for the design.
Here's an example of a notebook with sparklines: https://github.com/iiSeymour/sparkline-nb/blob/master/sparkline-nb.ipynb. I like the way that the notebook has a single column with series data in it. The alternative would be to somehow slice on the index and hide the cells.
I believe the style imports have changed in pandas 0.18.
I get ImportError: No module named style
Should be:
from pandas.formats.style import Styler
set_font
set_background
- change cell background coloursset_alternating
- apply alternating even-odd coloursset_hover
- apply hover effectsset_cell_height
- set minimum cell heightset_cell_width
- set minimum cell widthdescribe
- add stats similar to DataFrame.describe()
Hello,
It could be very useful to have a conda package for PrettyPandas.
$ conda install PrettyPandas
Fetching package metadata .........
PackageNotFoundError: Packages missing in current channels:
- prettypandas
We have searched for the packages in the following channels:
- https://repo.continuum.io/pkgs/free/osx-64
- https://repo.continuum.io/pkgs/free/noarch
- https://repo.continuum.io/pkgs/r/osx-64
- https://repo.continuum.io/pkgs/r/noarch
- https://repo.continuum.io/pkgs/pro/osx-64
- https://repo.continuum.io/pkgs/pro/noarch
Otherwise, installing using pip
works fine
$ pip install PrettyPandas
Collecting PrettyPandas
Downloading prettypandas-0.0.3.tar.gz
Requirement already satisfied: babel in ./anaconda/lib/python3.6/site-packages (from PrettyPandas)
Requirement already satisfied: ipython in ./anaconda/lib/python3.6/site-packages (from PrettyPandas)
Requirement already satisfied: numpy in ./anaconda/lib/python3.6/site-packages (from PrettyPandas)
Requirement already satisfied: jinja2 in ./anaconda/lib/python3.6/site-packages (from PrettyPandas)
Requirement already satisfied: pandas>=0.17.1 in ./anaconda/lib/python3.6/site-packages (from PrettyPandas)
Requirement already satisfied: pytz>=0a in ./anaconda/lib/python3.6/site-packages (from babel->PrettyPandas)
Requirement already satisfied: MarkupSafe>=0.23 in ./anaconda/lib/python3.6/site-packages (from jinja2->PrettyPandas)
Requirement already satisfied: python-dateutil>=2 in ./anaconda/lib/python3.6/site-packages (from pandas>=0.17.1->PrettyPandas)
Requirement already satisfied: six>=1.5 in ./anaconda/lib/python3.6/site-packages (from python-dateutil>=2->pandas>=0.17.1->PrettyPandas)
Building wheels for collected packages: PrettyPandas
Running setup.py bdist_wheel for PrettyPandas ... done
Stored in directory: /Users/scls/Library/Caches/pip/wheels/ad/41/3c/a3d331a42437852dd0f4aa8156f2563072a388fdb92d27c3dc
Successfully built PrettyPandas
Installing collected packages: PrettyPandas
Successfully installed PrettyPandas-0.0.3
Kind regards
Normally df.index.name = "XXX"
add's a header to the index column of a dataframe, however when using the Style API this doesn't work.
It needs to be investigated whether this is a pandas issue or hidden in the API somewhere.
Hi, the link to Pandas Style API (Features part) is incorrect in file Readme.md, "<" is unnecessary.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.