看板 Python 關於我們 聯絡資訊
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
handsomeLin: 他是問資料庫... 10/18 15:05
mychiux413: pandas可以操作資料庫, 把做好的df給他to_sql就可以了 10/21 22:29