我現有的資料框'錯誤'是這樣的,
| 巴爾1 | 巴爾2 | 巴爾3 |
|---|---|---|
| 1 | 2.0 | 1 |
| 3 | 鈉 | 3 |
I want to add a fourth column Bal4= [1,2,3,4,5]
所以,我確實將 pandas 匯入為 pd
錯誤['Bal4']= pd.Series(Bal4)
但后來我得到“錯誤”
| 巴爾1 | 巴爾2 | 巴爾3 | 巴爾4 | |
|---|---|---|---|---|
| 1 | 2.0 | 1 | 1 | |
| 3 | 鈉 | 3 | 2 | |
Bal4 的其余 3、4、5 被洗掉,為什么?
uj5u.com熱心網友回復:
嘗試pd.concat
error = pd.concat([error, pd.DataFrame({'Bal4': Bal4})], axis=1)
print(error)
Bal2 Bal3 Bal4
0 2.0 1.0 1
1 NaN 3.0 2
2 NaN NaN 3
3 NaN NaN 4
4 NaN NaN 5
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/457948.html
上一篇:如何根據PandasDataframe中的兩行加快分數計算?
下一篇:按多個標準對資訊進行分組?
