I have been trying to write a function to use with pandas style
. I want to highlight specific columns that I specify in the arguments. This is not very elegant, but for example:
data = pd.DataFrame(np.random.randn(5, 3), columns=list('ABC'))
def highlight_cols(df, cols, colcolor = 'gray'):
for col in cols:
for dfcol in df.columns:
if col == cols:
color = colcolor
return ['background-color: %s' % color]*df.shape[0]
then call with:
data.style.apply(highlight_cols(cols=['B','C']))
I get an error:
'Series' object has no attribute 'columns'
I think I fundamentally don't quite understand how the styler calls and apply
ies the function.