[Python] Python Great Tables does not save to PDF, but always to PNG

Discussão em 'Python' iniciado por Stack, Março 1, 2025.

  1. Stack

    Stack Membro Participativo

    from great_tables import GT
    from great_tables.data import sp500

    # Selenium 4, Firefox
    from selenium import webdriver
    from selenium.webdriver.firefox.service import Service as FirefoxService
    from webdriver_manager.firefox import GeckoDriverManager
    options = webdriver.FirefoxOptions()
    options.add_argument("--headless")
    driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()), options=options)

    # Define the start and end dates for the data range
    start_date = "2010-06-07"
    end_date = "2010-06-14"

    # Filter sp500 using Pandas to dates between `start_date` and `end_date`
    sp500_mini = sp500[(sp500["date"] >= start_date) & (sp500["date"] <= end_date)]

    # Create a gt table based on the `sp500_mini` table data
    (
    GT(sp500_mini)
    .tab_header(title="S&P 500", subtitle=f"{start_date} to {end_date}")
    .fmt_currency(columns=["open", "high", "low", "close"])
    .fmt_date(columns="date", date_style="wd_m_day_year")
    .fmt_number(columns="volume", compact=True)
    .cols_hide(columns="adj_close")
    ).save(
    file="test.pdf",
    web_driver=driver,
    window_size=(6000, 6000)
    )


    In the above code the output file is saved as "test.png". This image file works fine, but it's not a pdf. When using the following in the save-method (and without the selenium block):

    webdriver = "firefox"


    The following error occurs:

    InvalidArgumentException: Message: binary is not a Firefox executable


    How do I save a great table to pdf?

    Continue reading...

Compartilhe esta Página