Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #change #colour #rows #csv #pandas
ADD COMMENT
Topic
Name
7+3 =