Apply Number Formatting to Pandas CSS CSS Styling

Pandas has a new styling option for formatting CSS ( http://pandas.pydata.org/pandas-docs/version/0.17.1/generated/pandas.core.style.Styler.html ).

Previously, when I wanted to make my numbers in accounting / dollar terms, I would use something like below:

df = pd.DataFrame.from_dict({'10/01/2015': {'Issued': 200}}, orient='index') html = df.to_html(formatters={'Issued': format_money}) 

Format_money function:

 def format_money(item): return '${:,.0f}'.format(item) 

Now I want to use the style options and save the $ format. I see no way to do this.

Style formatting, for example, would look something like this:

  s = df.style.bar(color='#009900') #df = df.applymap(config.format_money) -- Doesn't work html = s.render() 

This will add bars to my HTML table as shown below (Docs here: http://pandas.pydata.org/pandas-docs/stable/style.html ):

from http: // pandas.pydata.org/pandas -docs / stable / style.html

So, how can I do something like adding bars, and also save or add dollar formatting to the table? If I try to do this earlier, the style lines do not work, because now they cannot say that the data is numerical and there are no errors. If I try to do this after, it overrides the style.

+5
source share
1 answer

This has not yet been implemented (version 0.17.1) - but for this there is a transfer request ( https://github.com/pydata/pandas/pull/11667 ) and should go to 0.18. For now, you should stick to using formatters.

+2
source

Source: https://habr.com/ru/post/1236635/


All Articles