Getting started¶
Using df2img, it's pretty straightforward to save a pd.DataFrame
into an image file. Let's first create a pd.DataFrame
for illustrative purposes.
In [1]:
Copied!
import pandas as pd
import df2img
df = pd.DataFrame(
data={
"float_col": [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={
"float_col": [1.4, float("NaN"), 250, 24.65],
"str_col": ("string1", "string2", float("NaN"), "string4"),
},
index=["row1", "row2", "row3", "row4"],
)
df
Out[1]:
float_col | str_col | |
---|---|---|
row1 | 1.40 | string1 |
row2 | NaN | string2 |
row3 | 250.00 | NaN |
row4 | 24.65 | string4 |
Saving df
into a png-file now takes just two lines of code, including some styling out of the box.
First, we create a plotly
figure.
In [2]:
Copied!
fig = df2img.plot_dataframe(df, fig_size=(600, 140))
fig = df2img.plot_dataframe(df, fig_size=(600, 140))
Second, we save the figure to disk.
In [3]:
Copied!
df2img.save_dataframe(fig=fig, filename="./img/getting_started.png")
df2img.save_dataframe(fig=fig, filename="./img/getting_started.png")