Always the best answers here from the community and that the image is perfectly formatted, that perfectly fits the columns according to the data, without loss of quality, the use of dataframe-image
is indicated:
https://stackoverflow.com/a/65954710/11462274
https://stackoverflow.com/a/70550426/11462274
The use is simplified and takes up almost no space in the code, a single line to call the function does all the work.
Official module page:
https://github.com/dexplo/dataframe_image
https://pypi.org/project/dataframe-image/
When using this module, several future alert messages about changes are issued, the code has become old and no longer update according to my research. This may cause problems in the future if a module is updated and no longer accepts the use of some function.
Like for example:
FutureWarning: this method is deprecated in favour of `Styler.to_html()`
html = '<div>' + obj.render() + '</div>'
I use it to save a stylized DataFrame in image:
import pandas as pd
import dataframe_image as dfi
def csv_to_image(csv_file,name_file):
df = pd.read_csv(csv_file)
df = df.style.set_table_styles([dict(selector='th', props=[('text-align', 'center'),('background-color', '#40466e'),('color', 'white')])])
df.set_properties(**{'text-align': 'center'}).hide(axis='index')
pd.set_option('colheader_justify', 'center')
dfi.export(df, name_file + ".png")
I would like to know if there is any module that does the same service and that has not been left out by the created.
My CSV data for example to tests:
DATA,HORA,CAMPEONATO,JOGO,CANAIS
21/04/2022,"08:00 Ao vivo 77'",Liga dos Campeões Asiática,0 Shandong Taishan x 0 Lion City Sailors FC,STAR+
21/04/2022,"08:00 Ao vivo 78'",Liga dos Campeões Asiática,2 BG Pathum United x 0 United City,STAR+
21/04/2022,11:00,Liga dos Campeões Asiática,Kawasaki Frontale x Johor Darul Takzim,STAR+
21/04/2022,11:00,Liga dos Campeões Asiática,Melbourne City x Jeonnam Dragons,STAR+
21/04/2022,11:00,Liga dos Campeões Asiática,Daegu FC x Urawa Red Diamonds,STAR+
21/04/2022,14:00,LaLiga,Espanhol x Rayo Vallecano,STAR+
21/04/2022,14:00,LaLiga,Levante x Sevilla,"ESPN 4, STAR+"
21/04/2022,15:00,LaLiga,Cadiz x Athletic Bilbao,"ESPN 3, STAR+"
21/04/2022,15:00,Campeonato Equatoriano,Mushuc Runa x Macara,STAR+
21/04/2022,15:45,Campeonato Inglês,Burnley x Southampton,"ESPN 2, STAR+"
21/04/2022,16:00,Copa da Liga Argentina,Sarmiento x Defensa y Justicia,STAR+
21/04/2022,16:15,Taça de Portugal,FC Porto x Sporting,STAR+
21/04/2022,16:30,LaLiga,Real Sociedad x Barcelona,"ESPN, STAR+"
21/04/2022,16:30,Brasileirão Série B,Grêmio x Guarani,PREMIERE FC
21/04/2022,16:30,Campeonato Pernambucano,Náutico x Retrô FC Brasil,"GLOBO(PE), PREMIERE 2"
21/04/2022,17:00,Campeonato Piauiense,Parnahyba x Fluminense PI,ELEVENSPORTS.COM
21/04/2022,17:30,Campeonato Equatoriano,SD Aucas x U Católica,STAR+
21/04/2022,19:00,Brasileirão Série B,Londrina x Grêmio Novorizontino,"PREMIERE FC, SPORTV"
21/04/2022,19:00,Campeonato Acreano,Rio Branco AC x Galvez AC,ELEVENSPORTS.COM
21/04/2022,19:00,Campeonato Capixaba,Serra x Real Noroeste Capixaba,"TVE(ES), YOUTUBE(TVE ES)"
21/04/2022,20:00,Campeonato Equatoriano,Cumbaya FC x Emelec,STAR+
21/04/2022,21:30,Copa do Brasil,Atlético GO x Cuiabá EC,"SPORTV, PREMIERE FC"
And the final result:
You could use
pandas
.to_html()
, then useimgkit
to write to file.