python 错误提示A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead解决方案

目标想根据kaohao新增加一个变量,其值用来标记kaohao是否连续 

解决方案:

>>> df4=df3[["kaohao"]].copy()
>>> df4['consecutive'] = (df4['kaohao']!= df4['kaohao'].shift(+1)).cumsum() 

 

posted @ 2024-01-28 06:28  myrj  阅读(174)  评论(0编辑  收藏  举报