title: How to color a dataframe to a conditional heatmap with same color across whole row based on a single column
body: <p>So I have a dataframe which looks like:</p>
  <pre><code>Target, Achieved, Goal, Remaining
  10, 5, 50, 5
  4, 5, 125, 0
  3, 3, 100, 0
  8, 2, 25, 6
  </code></pre>
  <p>I want to display this dataframe with visible info based on colors, Under this criteria:</p>
  <ol>
  <li>If goal is achieved I just wanted row to be green regardless of how surpassed goal actually is. So the whole 2nd and 3rd rows would be the same green color</li>
  <li>If goal is not achieved, I want to color them based on heatmap. So here I want 4th row to be a darker shade (of lets say red) than 1st row since I am missing more on that row's goal.</li>
  </ol>
  <p>For single color, following function works perfectly: Thanks to the answer <a href="https://stackoverflow.com/questions/47469478/how-to-color-whole-rows-in-python-pandas-based-on-value">here</a></p>
  <pre><code>def highlight_col(x):
      #copy df to new - original data are not changed
      df = x.copy()
      #set by condition
      mask = df['Goal Completion (%)'] &gt;= 100
      df.loc[mask, :] = 'background-color: lightgreen'
      df.loc[~mask,:] = 'background-color: pink'
      return df      
  </code></pre>
  <p>For a simple heatmap without excluding Goal completion condition, its possible via:</p>
  <pre><code>df.style.background_gradient(cmap='Reds')
  </code></pre>
  <p>But it:</p>
  <ol>
  <li>Includes whole dataframe</li>
  <li>Color by each column separately</li>
  <li>Cannot exclude rows with goals achieved</li>
  <li>Could not be used inside my above function (tried using: <code>df.loc[~mask,:] = 'background_gradient: Reds'</code> in last line but didn't work either.</li>
  </ol>
  <p>P.S. My Dataframe isn't very large so I prefer table coloring itself from where I can select rows instead of having a whole new viz. Any suggestions bettering the situation are highly welcomed!</p>
  <h2>Sample output:</h2>
  <p><a href="https://i.stack.imgur.com/uLTkc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uLTkc.png" alt="enter image description here" /></a></p>