Is there an option to drop the index in the image?
Is this possible?
I had the same question. I am not sure of the correct final design here, and the below would be a DataFrame-only solution. It is possible this could be solved by Styler, but I don't know much about that yet. I would propose a new parameter to export to take a show_table_index parameter which could default to True and not break current design.
In the following file:
C:\Users\[username]\AppData\Roaming\Python\Python39\site-packages\dataframe_image\_pandas_accessor.py
I changed line 71 from:
html = obj.to_html(max_rows=max_rows, max_cols=max_cols, notebook=True)
to:
df = pd.DataFrame(obj)
html = df.to_html(index=False, max_rows=max_rows, max_cols=max_cols, notebook=True)
and passing index=False to the to_html() call.
Thanks. This did work for me as a temporary solution.
@korygill Thanks for this solution! I just tried it and it worked on my development machine. However, when I tried implementing it on my server, it broke my site (I suspect it was an issue with gunicorn). But that's an issue for a different thread.
@korygill @trlemon I figured out how to drop the index and keep other styles as well (for example, I'm going to hide the index and apply a background gradient). Define df_styled prior to the export:
df_styled = df.style.hide().background_gradient()
dfi.export(df_styled, 'df_styled.png')
The pandas documentation: https://pandas.pydata.org/docs/user_guide/style.html#Hiding-Data Suggests formatting like:
df_styled = df.style.hide() \
.background_gradient()
dfi.export(df_styled, 'df_styled.png')