這篇文章給大家介紹利用pandas怎么對數(shù)據(jù)進行導出,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
具體方法如下:
import pandas as pd import pymysql df = pd.DataFrame({'A': [3, 4, 8, 9], 'B': [1.2, 2.4, 4.5, 7.3], 'C': ["aa", "bb", "cc", "dd"]}) def export_data_to_csv(): # 參數(shù)encoding="utf_8_sig"編碼后,可以防止寫入csv的中文出現(xiàn)亂碼 df.to_csv("./test.csv", encoding="utf_8_sig") def export_data_to_excel(): # encoding編碼方式,sheet_name表示要寫到的sheet名稱, 默認為0, header=None表示不含列名 df.to_excel("./test.xlsx", encoding="utf_8_sig", sheet_name=0, header=None) def export_data_to_table(): con = pymysql.connect(host="127.0.0.1", user="username", password="password", database="dbname", charset='utf8', use_unicode=True) df.to_sql(name='table_name', con=con, if_exists='append', index=False) def export_data_to_json(): df.to_json("test.txt") def main(): export_data_to_csv() # 導出數(shù)據(jù)到CSV文件 export_data_to_excel() # 導出數(shù)據(jù)到Excel文件 export_data_to_table() # 導出數(shù)據(jù)到SQL表 export_data_to_json() # 以Json格式導出數(shù)據(jù)到文本文件 if __name__ == '__main__': main()
關于利用pandas怎么對數(shù)據(jù)進行導出就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
網(wǎng)頁名稱:利用pandas怎么對數(shù)據(jù)進行導出-創(chuàng)新互聯(lián)
URL分享:http://jinyejixie.com/article20/dcphco.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、網(wǎng)站營銷、Google、網(wǎng)站設計公司、網(wǎng)站建設、營銷型網(wǎng)站建設
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內容