作者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://webptt.com/cn.aspx?n=bbs/Python/M.1539829687.A.B47.html
1F:推 handsomeLin: 他是问资料库... 10/18 15:05
2F:推 mychiux413: pandas可以操作资料库, 把做好的df给他to_sql就可以了 10/21 22:29