S
S
shell_guy2021-12-15 18:39:22
Python
shell_guy, 2021-12-15 18:39:22

How to connect pandas directly to db instead of feeding csv?

Good day!
Please tell me the code, how to connect with either pandas to fetch data from a table?
I figured out csv, it's not difficult, but what about the database? There is not much data, but you need to see the statistics
Thank you

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2021-12-15
@rozhnev

con = pymysql.connect(
            host='sql_host', port=sql_port,
            user=sql_username, passwd=sql_password, 
            db=sql_database,
    )
    df=pd.read_sql_query(sql, con)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question