Last active
May 13, 2020 17:24
-
-
Save aboucaud/0546cdf6e8d9a359e81f7473a14b7b19 to your computer and use it in GitHub Desktop.
[Pandas table styling] #python #visualisation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://pandas.pydata.org/pandas-docs/stable/reference/style.html | |
| # https://towardsdatascience.com/style-pandas-dataframe-like-a-master-6b02bf6468b0 | |
| import pandas as pd | |
| # Option examples | |
| pd.set_option('precision', 4) | |
| pd.set_option('max_rows', 10) | |
| pd.set_option('max_columns', 7) | |
| pd.set_option("display.max_colwidth", -1) | |
| # Table styling | |
| (df.head(10) | |
| .style | |
| .format({ | |
| "Dollars": "${:20,.0f}", | |
| "Euros": "{:20,.0f}€", | |
| "Title": lambda x: x.lower()}) | |
| .hide_index() | |
| .background_gradient(subset=["Dollars"], cmap='Reds') | |
| .bar(subset=["Euros"], color='lightgreen')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment