Controlling the index column¶
df2img provides some possibilites to control how the index column will be printed/saved to an image file.
First thing to mention is the fact that the index column header cell is dependent on the index name of the dataframe.
If you want to omit a header for the index column, you have to set the index name of the dataframe to an empty string:
df.index.name = ""
.
Index header cell¶
In [1]:
Copied!
import pandas as pd
import df2img
df = pd.DataFrame(
data={
"value_col_1": [1.4, float("NaN"), 250, 24.65],
"str_col": ("string1", "string2", float("NaN"), "string4"),
},
index=["row1", "row2", "row3", "row4"],
)
df
import pandas as pd
import df2img
df = pd.DataFrame(
data={
"value_col_1": [1.4, float("NaN"), 250, 24.65],
"str_col": ("string1", "string2", float("NaN"), "string4"),
},
index=["row1", "row2", "row3", "row4"],
)
df
Out[1]:
value_col_1 | str_col | |
---|---|---|
row1 | 1.40 | string1 |
row2 | NaN | string2 |
row3 | 250.00 | NaN |
row4 | 24.65 | string4 |
Setting the index name at the dataframe level:
In [2]:
Copied!
df.index.name = "row_number"
df
df.index.name = "row_number"
df
Out[2]:
value_col_1 | str_col | |
---|---|---|
row_number | ||
row1 | 1.40 | string1 |
row2 | NaN | string2 |
row3 | 250.00 | NaN |
row4 | 24.65 | string4 |
In [3]:
Copied!
fig = df2img.plot_dataframe(
df, title={"text": "Table with index header"}, fig_size=(600, 140)
)
fig = df2img.plot_dataframe(
df, title={"text": "Table with index header"}, fig_size=(600, 140)
)
Omitting the index column¶
df2img provides the keyword argument print_index
, which, if set to True
, prints the index column.
If it is set to False
, the dataframe's index column will simply be ignored/not printed at all.
In [4]:
Copied!
fig = df2img.plot_dataframe(
df,
print_index=False,
title={"text": "Table without index column"},
fig_size=(600, 140),
)
fig = df2img.plot_dataframe(
df,
print_index=False,
title={"text": "Table without index column"},
fig_size=(600, 140),
)