作者iftrush (靈感喪失的痛)
看板Python
標題Re: [問題] 如何把資料寫入資料庫的一個新的column裡
時間Thu Oct 18 10:28:03 2018
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