Skip to main content
added 101 characters in body
Source Link
Florian Bernard
  • 2.6k
  • 1
  • 11
  • 24

You should pass only the column name in your subset is wrongvariable. Also, try this insteadyour function should return a list with the same length as your column.

def _color_red_or_green(val): conditions = val > 2500 results = [] for v in conditions: if v: color = "red" else: color = "green" results.append(f"color : {color}") return results highlighted=df.style.apply(_color_red_or_green,subset=['cld_hgt']) 

your subset is wrong, try this instead.

def _color_red_or_green(val): conditions = val > 2500 results = [] for v in conditions: if v: color = "red" else: color = "green" results.append(f"color : {color}") return results highlighted=df.style.apply(_color_red_or_green,subset=['cld_hgt']) 

You should pass only the column name in your subset variable. Also, your function should return a list with the same length as your column.

def _color_red_or_green(val): conditions = val > 2500 results = [] for v in conditions: if v: color = "red" else: color = "green" results.append(f"color : {color}") return results highlighted=df.style.apply(_color_red_or_green,subset=['cld_hgt']) 
added 250 characters in body
Source Link
Florian Bernard
  • 2.6k
  • 1
  • 11
  • 24

your subset is wrong, try this instead.

def _color_red_or_green(val): conditions = val > 2500 results = [] for v in conditions: if v: color = "red" else: color = "green" results.append(f"color : {color}") return results highlighted=df.style.apply(_color_red_or_green,subset=['cld_hgt']) 

your subset is wrong, try this instead.

highlighted=df.style.apply(_color_red_or_green,subset=['cld_hgt']) 

your subset is wrong, try this instead.

def _color_red_or_green(val): conditions = val > 2500 results = [] for v in conditions: if v: color = "red" else: color = "green" results.append(f"color : {color}") return results highlighted=df.style.apply(_color_red_or_green,subset=['cld_hgt']) 
Source Link
Florian Bernard
  • 2.6k
  • 1
  • 11
  • 24

your subset is wrong, try this instead.

highlighted=df.style.apply(_color_red_or_green,subset=['cld_hgt'])