![](/img/trans.png)
[英]how to find if two rows of a column exist based on another column in a DataFrame?
[英]How to add a dataframe column based on two consecutive rows in another column
我在這個 pandas dataframe 中有 (A) 列
一種 | 乙 |
---|---|
1個 | 1個 |
1個 | 2個 |
2個 | 3個 |
5個 | 7 |
列 (B) 使用以下公式創建:
B列(2)= A列(1)+ A列(2)
如何從 A 列創建 (B) 列?
你可以做
df["B"] = df['A'] + df['A'].shift(1, fill_value= 0.)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.