当前位置:   article > 正文

Pandas的shift函数_pandas shift函数

pandas shift函数

Pandas的shift函数可以将DataFrame移动指定的位数。比如,
period参数指定移动的位数,axis参数指定轴向

import pandas as pd

df = pd.DataFrame({'a':[1,2,3], 'b':[4,5,6], 'c':[7,8,9]})
  • 1
  • 2
  • 3

在这里插入图片描述

df.shift(periods=1, axis=0) # 将df整体向下移动一位
  • 1

在这里插入图片描述

df.shift(periods=2, axis=1) # 将df整体向右移动两位
  • 1

在这里插入图片描述

计算每个小时的入口和出口人流量

# 这是从某时刻开始累积的人流量
entries_and_exits = pd.DataFrame({
    'ENTRIESn': [3144312, 3144335, 3144353, 3144424, 3144594,
                 3144808, 3144895, 3144905, 3144941, 3145094],
    'EXITSn': [1088151, 1088159, 1088177, 1088231, 1088275,
               1088317, 1088328, 1088331, 1088420, 1088753]
})

# 计算每小时出口和入口的人流量
entries_and_exits - entries_and_exits.shift(1)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/945378
推荐阅读
相关标签
  

闽ICP备14008679号