I am trying to use the string generated from rendering a styler in an email message. Seems really hard to get this to ignore the dataframe index.
table_styles = [dict(selector="tbody tr th", props=[("display", "none")]),
st=df.style.set_table_styles(table_styles)
st.render()
I have been able to sort of make it work with the display none CSS setting, but it works differently on different devices based on CSS support level.
Isn't there a way to make the index payload just go away ?
Drop the index column of Pandas DataFrame We can remove the index column in existing dataframe by using reset_index() function. This function will reset the index and assign the index columns start with 0 to n-1. where n is the number of rows in the dataframe.
Use hide_index() By using hide_index() method, you can hide the Index of the DataFrame.
Practical Data Science using Python To create a DataFrame from DateTimeIndex ignoring the index, use the DateTimeIndex. to_frame() method. Set the parameter index to False to ignore the index.
I think I have the same solution as yours and I am facing the same issue as you were (display is different on different devices). I am just writing down the partial solution here to help someone who is in search of the way to do it.
if you do html.render().split('\n')
you will be able to get the class structure related to the first column and index( if you have already used resent_index).
Styles can then be defined to get rid of those columns using CSS property of display.
# define the style related to first column and index here
# first-element : when index =True,
# second element: default index of the table generated by the Style
styles = [
dict(selector = ".col0", props = [('display', 'none')]),
dict(selector = "th:first-child", props = [('display', 'none')])
]
# set the table styles here
table.set_table_styles(styles)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With