title: Pandas - Apply Style/Formatting Based on Column Name and Value of a Row
body: <pre><code>import pandas as pd
  
  df2 = pd.DataFrame.from_records(
  {'Compared': {0: -0.090909090999999997,
    1: -0.130434783,
    2: -0.10714285699999999,
    3: -0.15966386599999999},
   'LastYR': {0: 5500.0, 1: 115.0, 2: 84.0, 3: 40520.523399999998},
   'METRIC': {0: 'Visits', 1: 'Units', 2: 'Orders', 3: 'Sales'},
   'Today': {0: 5000.0, 1: 100.0, 2: 75.0, 3: 34050.860000000001},
   'region_rollup': {0: 'America', 1: 'America', 2: 'America', 3: 'America'}}
  
  )
  df2.head()
  </code></pre>
  
  <p>How can I apply:</p>
  
  <p>a) a % format to any entire column I would like</p>
  
  <p>b) A currency $ format to any row where the METRIC value is 'Sales'</p>
  
  <p><a href="https://i.stack.imgur.com/2nn8X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2nn8X.png" alt="enter image description here"></a></p>
  
  <p>I have tried the df.style.format() function, which will let me subset columns and apply the % formatting, but I cannot determine what kind of function to write which would allow me to format a column, based on the value of another column (again, "if metric = sales then format today as currency", more or less). </p>
  
  <p>Thanks!</p>