[Python] Does pandas need to close connection?

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

  1. Stack

    Stack Membro Participativo

    When using pandas "read_sql_query", do I need to close the connection? Or should I use a "with" statement? Or can I just use the following and be good?

    from sqlalchemy import create_engine
    import pandas as pd

    sql = """
    SELECT * FROM Table_Name;
    """
    engine = create_engine('blah')

    df = pd.read_sql_query(sql, engine)

    print df.head()

    Continue reading...

Compartilhe esta Página