I want to format only specific columns of the dataframe. Right now styling gets
applied to every column, this can be done using subset parameter in df.style.background_gradient()
as per documentation. I tried to do subset = df.iloc[:, 3:] as I want to apply styling to column 3
onwards but I am getting too many indexers error.
import pandas as pd
import seaborn as sns
filename = r'c:\Users\91956\Desktop\time_50.csv'
df = pd.read_csv(filename)
cm = sns.light_palette("green", as_cmap=True)
s = df.style.background_gradient(cmap=cm, axis = 1)
html = s.render()
with open("output.html","w") as fp:
fp.write(html)
what is the correct way to write subset parameter so that styling applies only to the columns from index 3 afterwards.
after doing necessary changes.
import pandas as pd import seaborn as sns
filename = r'c:\Users\91956\Desktop\time_50.csv'
df = pd.read_csv(filename,index_col = 0)
cm = sns.light_palette("green", as_cmap=True)
select_col = df.columns[2:]
s = df.style.background_gradient(cmap=cm, axis = 1,subset=select_col)
html = s.render()
with open("output.html","w") as fp:
fp.write(html)