Skip to main content
 首页 » 编程设计

python之Pandas之操作系列和延迟

2025年05月04日15lhb25

我在 Pandas 中有以下数据框。我的疑问是我怎样才能在有时间延迟的系列中进行操作。例如,我想计算一个时期的GDP除以下一时期的人口的结果。

         GDP     Population 
1950     3.31        1 
1951     3.5         1 
... 
2000     15.2        2 

请您参考如下方法:

为此你可以使用:

df['new_col'] = df['GDP'] / df['Population'].shift(1)