Using PyCharm to Read Data From a MySQL DataBase Into pandas import mysql.connector as sql import pandas as pd db_connection = sql.connect(host='hostname', database='db_name', user='username', password='password') db_cursor = db_connection.cursor() db_cursor.execute('SELECT * FROM table_name') table_rows = db_cursor.fetchall() df = pd.DataFrame(table_rows)
print the data frame Here is an example output:
0 1 2 3 4 5 6 7 8 0 :ID[giA0CqQcx+(9kbuSKV== NaN NaN None None None None None None 1 lXB+jIS)DN!CXmj>0(P8^]== NaN NaN None None None None None None 2 lXB+jIS)DN!CXmj>0(P8^]== NaN NaN None None None None None None 3 lXB+jIS)DN!CXmj>0(P8^]== NaN NaN None None None None None None 4 lXB+jIS)DN!CXmj>0(P8^]== NaN NaN None None None None None None
Use pandas for reading data from your MySQL server because it would be much more efficient:df = pd.read_sql('SELECT * FROM table_name', con=db_connection)
|