Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to change colour of rows in csv using pandas

import numpy as np
import pandas as pd


df = pd.DataFrame([[8484,-1.15],[1390,3.5],[327,10.5],[1135,3.3],[6499,2.0],[1055,4.0]], columns=['data1','dat2'])


def color_rule(val):
    return ['background-color: red' if x >= 3 else 'background-color: yellow' for x in val]

html_column = df.style.apply(color_rule, axis=1, subset=['dat2'])

html_column.to_excel('styled.xlsx', engine='openpyxl')

html_column
Comment

how to change colour of rows in csv using pandas

import numpy as np
import pandas as pd


df = pd.DataFrame([['ex1',8484,-1.15],['ex2',1390,3.5],['ex3',327,10.5],['ex4',1135,3.3],['ex5',6499,2.0],['ex6',1055,4.0]], columns=['tag','data1','dat2'])


def color_rule(tag):
    var1 = df['dat2'][df['tag'] == tag.values[0]]
    return ['background-color: red' if x >= 3 else 'background-color: yellow' for x in var1]

html_column = df.style.apply(color_rule, axis=1, subset=['tag'])

html_column.to_excel('styled.xlsx', engine='openpyxl')
Comment

PREVIOUS NEXT
Code Example
Python :: add a dot in a long number in python 
Python :: python read text file into a list 
Python :: how to convert list to tensor pytorch 
Python :: how to get input from user in python 
Python :: triangle pattern in python 
Python :: mish activation function tensorflow 
Python :: python default dictonary 
Python :: valid parentheses with python 
Python :: check os python 
Python :: get number of bits for integer in python 
Python :: exit python script 
Python :: generate valid sudoku board python 
Python :: python program to give shop name 
Python :: how to make player quit in python 
Python :: open administrator command prompt using python 
Python :: Python Split list into chunks using List Comprehension 
Python :: export a dataframe from rstudio as csv 
Python :: how to pipe using sybprosses run python 
Python :: shuffle array python 
Python :: where to find python interpreter 
Python :: drop rows in list pandas 
Python :: django datetimefield default 
Python :: pyspark select without column 
Python :: install chromedriver ubuntu python 
Python :: exclude columns in df 
Python :: networkx create graph from dataframe 
Python :: matplotlib add legend axis x 
Python :: rotational list python 
Python :: python display map 
Python :: requests post with headers python 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =