pandas DataFrame 有resample如下方法,我想通过在 BigQuery 中查询来实现等价的方法。
pandas 中的示例方法
现在我有这样的数据。假设相同的数据存储在 bigquery 中。
In [2]: df.head()
Out[2]:
Open High Low Close Volume
Gmt time
2016-01-03 22:00:00 1.08730 1.08730 1.08702 1.08714 8.62
2016-01-03 22:01:00 1.08718 1.08718 1.08713 1.08713 3.75
2016-01-03 22:02:00 1.08714 1.08721 1.08714 1.08720 4.60
2016-01-03 22:03:00 1.08717 1.08721 1.08714 1.08721 7.57
2016-01-03 22:04:00 1.08718 1.08718 1.08711 1.08711 5.52
Run Code Online (Sandbox Code Playgroud)
然后使用 DataFrame 以 5 分钟的频率重新采样数据。
In [3]: ohlcv = {
: 'Open':'first',
: 'High':'max',
: 'Low':'min',
: 'Close':'last',
: 'Volume':'sum'
: } …Run Code Online (Sandbox Code Playgroud)