'Styler' object has no attribute 'hide_index' Error

Hi could someone help me correct this error I’m getting?
‘Styler’ object has no attribute ‘hide_index’
Traceback (most recent call last):
File “”, line 78, in
AttributeError: ‘Styler’ object has no attribute ‘hide_index’

Hi @aortiz19 , given that this is a problem with Python code rather than specifically KNIME, it would be better in this situation to supply the whole code as text rather than as a screenshot.

You haven’t told us anything about how you have defined output_table_0 and what kind of object it represents, although I gather from the methods you are using that it is probably a pandas dataframe.

From googling, Pandas dropped the hide_index() method in v2.0. It looks like the render() method is also deprecated.

Instead of

output_table.style.hide_index().render()
try this:

output_table.style.hide(axis="index").to_html()

btw, I assume that instead of using output_table_0.style., you had intended using html. since you appear to have an unused object called html

I can’t test this out at the moment so I hope the above helps fix the problem.

1 Like

Hi thank you so much for your response, yes I did intend to use html originally that part of the code looked like this:
#Generate HTML from panda dataframe and apply styling
html = output_table_1.style
.applymap(color_recommend_pass, subset=[‘Pass’])
.applymap(color_recommend_fail, subset=[‘Fail’])
.applymap(color_recommend_supress, subset=[‘Ignored’])
.applymap(color_recommend_outlier, subset=[‘Outlier’])
.set_properties(**{‘min-width’:‘75px’,‘text-align’: ‘center’})
.set_table_styles([style_th,col_styles])
.hide_index().render()
and this was working code that was used before but for some reason didn’t work for me so I had to make some edits (what you saw in my original post).
Since your reply I have made changes and added the line you gave and now that part works! But I am running into another error:
“File “”, line 90, in
File “C:\ProgramData\Miniconda3\lib\re.py”, line 241, in findall
return _compile(pattern, flags).findall(string)
TypeError: expected string or bytes-like object”

This is my full code, again appreciate the help:
import pandas as pd
from datetime import datetime
import re
import numpy as np

#Copy input to output
output_table_1 = input_table_1.copy()
output_table_2 = input_table_2.copy().rename_axis(‘Page’).reset_index(level=0)

output_table_1[‘url’] = ‘https://docs.google.com/spreadsheets/d/’ + input_table_1[‘Workbook_ID’] + ‘/edit#gid=’ + input_table_1[‘Sheet_ID’]
output_table_1[‘Page’] = “” + output_table_1[‘Page’] +“

output_table_1 = output_table_1[[‘Page’, ‘Pass’, ‘Fail’, ‘Outlier’, ‘Ignored’]]

#Styling color pink/green based on status
def color_recommend_fail(value):
if value > 0:
color = ‘pink’
elif value <= 0:
color = ‘lightgreen’
else:
return
return f’background-color: {color}’

#Styling color pink/green based on status
def color_recommend_pass(value):
if value > 0:
color = ‘lightgreen’
elif value <= 0:
color = ‘pink’
else:
return
return f’background-color: {color}’

#Styling color pink/green based on status
def color_recommend_outlier(value):
if value > 0:
color = ‘#FCFF91
elif value <= 0:
color = ‘lightgreen’
else:
return
return f’background-color: {color}’

#Styling color pink/green based on status
def color_recommend_supress(value):
if value > 0:
color = ‘#FFD07F
elif value <= 0:
color = ‘lightgreen’
else:
return
return f’background-color: {color}’

#Collapse table boards together (not working)
style_th = dict(selector=“th”, props=[
(‘border-collapse’, ‘collapse’),
(‘background-color’, ‘black’),
(‘color’, ‘white’),
(‘font-size’, ‘17px’)])

col_styles = dict(selector=‘.col0’, props=[
(‘min-width’, ‘50px’),
(‘text-align’, ‘left’),
(‘padding-left’, ‘10px’),
(‘font-weight’, ‘bold’)])

#Generate HTML from panda dataframe and apply styling
html = output_table_1.style
output_table_1.style.applymap(color_recommend_pass, subset=[‘Pass’])
output_table_1.style.applymap(color_recommend_fail, subset=[‘Fail’])
output_table_1.style.applymap(color_recommend_supress, subset=[‘Ignored’])
output_table_1.style.applymap(color_recommend_outlier, subset=[‘Outlier’])
output_table_1.style.set_properties(**{‘min-width’:‘75px’,‘text-align’: ‘center’})
output_table_1.style.set_table_styles([style_th,col_styles])
output_table_1.style.hide(axis=“index”).to_html()

#Generate HTML from panda dataframe and apply styling
html2 = output_table_2.style
output_table_2.style.applymap(color_recommend_fail, subset=[‘Row Delta’])
output_table_2.style.applymap(color_recommend_supress, subset=[‘Total Retries’])
output_table_2.style.set_properties(**{‘min-width’:‘75px’,‘text-align’: ‘center’})
output_table_2.style.set_table_styles([style_th,col_styles])
#.hide_index().render()

#KNIME python outdated and only supports render. Will manually wrap components for Gmail html parsing
flow_variables[‘style_html’] = re.findall(‘<style[\S\n\t\v ]+</style>’, html)[0]
flow_variables[‘body_html’] = re.findall(‘<table[\S\n\t\v ]+</table>’, html)[0]

#KNIME python outdated and only supports render. Will manually wrap components for Gmail html parsing
flow_variables[‘style_html2’] = re.findall(‘<style[\S\n\t\v ]+</style>’, html2)[0]
flow_variables[‘body_html2’] = re.findall(‘<table[\S\n\t\v ]+</table>’, html2)[0]

print(flow_variables[‘body_html’])

Hi @aortiz19, I can code some python and generally do some debugging, but faced with a script and no data with which to run it, I’m going to struggle. I’m not that good!! :wink:

Also, as it stands I can’t even paste the code into a python script as you need to mark it as “preformatted text” in your post, because the quotes (and possibly other things) are all wrong
image

The best I can do is ask chatGPT, so this is its response:

reproduced here:

The error you’re encountering indicates a TypeError in the re.findall function. The error message suggests that the findall function expects a string or bytes-like object, but it’s not receiving one.

In your code, you are trying to extract HTML code from the styled DataFrames (output_table_1 and output_table_2) using regular expressions. However, it seems that you are trying to apply styling to the DataFrames after calling .to_html(), and this may be causing the issue.

Here are a few suggestions to resolve the problem:

  1. Apply styling before calling .to_html(): Move the styling code before converting the DataFrames to HTML. Apply the styling using the .applymap and other styling methods on the DataFrame, and then call .to_html().

Do the same for output_table_2.

  1. Check the types of variables: Ensure that the variables you are passing to re.findall are of the correct type (string or bytes-like).
  2. Debugging: Print intermediate values to understand the state of your variables before calling re.findall. For example, print the values of html and html2 before using re.findall to see if they contain the expected content.

By applying styling before converting to HTML, you should be able to resolve the TypeError. If the issue persists, check the types of the variables and the content of the HTML strings you are trying to parse with regular expressions.


Unfortunately to me this isn’t really a KNIME question, it’s a python question.

Somebody else here may be able to spot the specific problem but if you want more assistance with this from me, or possibly somebody else, I’m afraid you’d have to upload a workflow with the data with which to run the script, and also describe what your expected outcome is. You may have to include an html file with your workflow in place of the “Google Sheets” doc.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.