Python-数据聚合 (Python - Data Aggregation)
Python has several methods are available to perform aggregations on data. It is done using the pandas and numpy libraries. The data must be available or converted to a dataframe to apply the aggregation functions.
Python有几种方法可用于对数据执行聚合。 它是使用pandas和numpy库完成的。 数据必须可用或转换为数据框才能应用聚合功能。
在DataFrame上应用聚合 (Applying Aggregations on DataFrame)
Let us create a DataFrame and apply aggregations on it.
让我们创建一个DataFrame并对其应用聚合。
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randn(10, 4),
index = pd.date_range('1/1/2000', periods=10),
columns = ['A', 'B', 'C', 'D'])
print df
r = df.rolling(window=3,min_periods=1)
print r
Its output is as follows −
其输出如下-
A B C D
2000-01-01 1.088512 -0.650942 -2.547450 -0.566858
2000-01-02 0.790670 -0.387854 -0.668132 0.267283
2000-01-03 -0.575523 -0.965025 0.060427 -2.179780
2000-01-04 1.669653 1.211759 -0.254695 1.429166
2000-01-05 0.100568 -0.236184 0.491646