title: Conditional bipolar inside table bar chart - pandas - css
body: <p>for my <strong>html</strong> representation of a pandas dataframe (python), I'd like to create something that resembles as much as possible the image below (created with Excel), that is, given a sequence of numbers, create <strong>INSIDE A TABLE</strong>, some horizontal bar charts that become green if the value is greater than zero, red if they are below zero and with the "zero" point in the axis which dynamically rescales according to the data provided. the closest I got to was by using pandas native instruments is given by the code below (<a href="http://pandas.pydata.org/pandas-docs/stable/style.html" rel="nofollow noreferrer">http://pandas.pydata.org/pandas-docs/stable/style.html</a>)
  <a href="https://i.stack.imgur.com/P2qOd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P2qOd.png" alt="enter image description here"></a></p>
  
  <pre><code>#done in Jupyter
  from pandas import DataFrame
  
  df = pd.DataFrame([-0.02, 0.03, 0.04, -0.05], columns=['A'])
  
  more_than_zero = df.loc[df.loc[:,'A'] &gt;= 0].index.values.tolist()
  less_than_zero = df.loc[df.loc[:,'A'] &lt; 0].index.values.tolist()
  
  df.style.bar(subset=pd.IndexSlice[more_than_zero,'A'], color='#d65f5f')
  #df.style.bar(subset=pd.IndexSlice[less_than_zero, 'B'], color='#7fff00')
  </code></pre>