pandas 数据实现行间计算的方法

如下所示:

###方法1:用shift函数,不用通过循环

import pandas as pd
import numpy as np
import matplotlib as plt
df = pd.DataFrame(np.random.randn(6,4),index=dates,columns=list('ABCD'))
df['diff'] = df['A'] - df['A'].shift(1)

相关推荐