我有三个数值列表:
jac = [0.66,0.8,0.2,0.5,0.3]
sor = [0.8,0.8,0.2,0.5,0.7]
diff = [1,0.8,0.2,0.5,0.5]
和现有的pandas DataFrame(df):
ham
0 0.5
1 0.6
2 0.6
3 0.7
4 0.9
以下是解决方案
df.assign(diff=diffl).assign(sor=sor).assign(jac=jac)
有哪些方法可以一次性附加这些列表?
答案 0 :(得分:3)
你可以这样做:
df.assign(diff=diffl,sor=sor,jac=jac)
答案 1 :(得分:3)
使用pd.concat
A=[jac,sor,diff]
pd.concat([DF,pd.DataFrame(A).T],axis=1).rename(columns={0:'jac',1:'sor',2:'diff'})
Out[2309]:
ham jac sor diff
0 0.5 0.66 0.8 1.0
1 0.6 0.80 0.8 0.8
2 0.6 0.20 0.2 0.2
3 0.7 0.50 0.5 0.5
4 0.9 0.30 0.7 0.5