設為首頁收藏本站

艾歐踢論壇

 找回密碼
 立即註冊

QQ登錄

只需一步,快速開始

搜索
熱搜: 活動 交友 discuz
查看: 294|回復: 0
打印 上一主題 下一主題

Using PyCharm to Read Data From a MySQL DataBase Into pandas

[複製鏈接]
跳轉到指定樓層
樓主
發表於 2023-4-5 20:47:20 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
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)



分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 轉播轉播 分享分享 分享淘帖
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

小黑屋|Archiver|手機版|艾歐踢創新工坊    

GMT+8, 2024-5-15 15:59 , Processed in 0.244765 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表