export a pandas dataframe as a table image

Solutions on MaxInterview for export a pandas dataframe as a table image by the best coders in the world

showing results for - "export a pandas dataframe as a table image"
Shana
11 Jan 2019
1from bokeh.io import export_png, export_svgs
2from bokeh.models import ColumnDataSource, DataTable, TableColumn
3
4def save_df_as_image(df, path):
5    source = ColumnDataSource(df)
6    df_columns = [df.index.name]
7    df_columns.extend(df.columns.values)
8    columns_for_table=[]
9    for column in df_columns:
10        columns_for_table.append(TableColumn(field=column, title=column))
11
12    data_table = DataTable(source=source, columns=columns_for_table,height_policy="auto",width_policy="auto",index_position=None)
13    export_png(data_table, filename = path)