Re: [問題] 如何把資料寫入資料庫的一個新的column裡

看板Python作者 (靈感喪失的痛)時間6年前 (2018/10/18 10:28), 編輯推噓2(200)
留言2則, 2人參與, 6年前最新討論串2/2 (看更多)
import numpy as np import pandas as pd frame = pd.DataFrame((np.arange(12) + 1).reshape(4,3), columns = list('ABC'), index = [1,2,3,4]) columns2 = list('ABCD') frame2 = frame.reindex(columns = columns2) lt = list([13,14,15,16]) frame2.loc[:,'D'] = lt print(frame2) 結果: A B C D 1 1 2 3 13 2 4 5 6 14 3 7 8 9 15 4 10 11 12 16 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 207.62.238.193 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1539829687.A.B47.html

10/18 15:05, 6年前 , 1F
他是問資料庫...
10/18 15:05, 1F

10/21 22:29, 6年前 , 2F
pandas可以操作資料庫, 把做好的df給他to_sql就可以了
10/21 22:29, 2F
文章代碼(AID): #1Rn--tj7 (Python)
文章代碼(AID): #1Rn--tj7 (Python)