【发布时间】:2015-12-01 08:44:07
【问题描述】:
我有一个 csv 文件,其中包含 3000 行和 5 列,每周都会不断地附加更多行。
我要做的是每周查找最后 1000 行的最后一列的算术平均值。 (所以当每周添加新行时,它只会取最近 1000 行的平均值)
我应该如何构造 pandas 或 numpy 数组来实现这一点?
df = pd.read_csv(fds.csv, index_col=False, header=0)
df_1 = df['Results']
#How should I write the next line of codes to get the average for the most 1000 rows?
【问题讨论】:
-
Based on the documentation,您应该利用
pandas的tails功能来获取最后1000 行。 -
谢谢!我知道头尾功能。但没想到我会以这种方式使用它。谢谢马特。
-
酷。如果下面的答案对您有所帮助,请务必接受它(或者如果有人发布了更好的答案)作为答案。