蓝绝

博客园 首页 新随笔 联系 订阅 管理

 

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#数据位移

#数据位移
import pandas as pd 
data=[7532, 3937, 9447, 8765, 4564] 
index=[1, 2, 3, 4, 5] 
df=pd. DataFrame (data=data, index=index, columns=['OPPO' ]) 
#print (df).
df['销量差']=df['OPPO' ]-df['OPPO'].shift(periods=1) #shift() 默认值为1,向下移动以为
print (df) 
#print (df['OPPO'].shift())
OPPO  销量差
1  7532     NaN
2  3937 -3595.0
3  9447  5510.0
4  8765  -682.0
5  4564 -4201.0

 

posted on 2022-11-20 17:37  蓝绝  阅读(32)  评论(0编辑  收藏  举报