3

Daily (ohlcv) を Weekly (ohlcv) にリサンプリング/変換したいと考えています。パンダでこれを行うことは可能ですか?

サンプルデータは次のとおりです (1 週間の毎日のデータ) 辞書形式:

   {'High': {<Timestamp: 2007-03-02 00:00:00>: 1384.5,
  <Timestamp: 2007-03-05 00:00:00>: 1373.0,
  <Timestamp: 2007-03-06 00:00:00>: 1378.75,
  <Timestamp: 2007-03-07 00:00:00>: 1381.75,
  <Timestamp: 2007-03-08 00:00:00>: 1388.75},
 'Last': {<Timestamp: 2007-03-02 00:00:00>: 1365.0,
  <Timestamp: 2007-03-05 00:00:00>: 1351.5,
  <Timestamp: 2007-03-06 00:00:00>: 1374.5,
  <Timestamp: 2007-03-07 00:00:00>: 1372.0,
  <Timestamp: 2007-03-08 00:00:00>: 1384.5},
 'Low': {<Timestamp: 2007-03-02 00:00:00>: 1364.25,
  <Timestamp: 2007-03-05 00:00:00>: 1350.5,
  <Timestamp: 2007-03-06 00:00:00>: 1362.0,
  <Timestamp: 2007-03-07 00:00:00>: 1370.75,
  <Timestamp: 2007-03-08 00:00:00>: 1369.25},
 'Open': {<Timestamp: 2007-03-02 00:00:00>: 1378.5,
  <Timestamp: 2007-03-05 00:00:00>: 1356.75,
  <Timestamp: 2007-03-06 00:00:00>: 1365.25,
  <Timestamp: 2007-03-07 00:00:00>: 1374.0,
  <Timestamp: 2007-03-08 00:00:00>: 1370.0},
 'Volume': {<Timestamp: 2007-03-02 00:00:00>: 1706906,
  <Timestamp: 2007-03-05 00:00:00>: 1984041,
  <Timestamp: 2007-03-06 00:00:00>: 1397911,
  <Timestamp: 2007-03-07 00:00:00>: 1255484,
  <Timestamp: 2007-03-08 00:00:00>: 798237}}
4

3 に答える 3

9

DataFrame にデータを取得したら、次の操作を実行できます。

 ohlc_dict = {
    'Open':'first',
    'High':'max',
    'Low':'min',
    'Close':'last',
    'Volume':'sum'
    }

DataFrame.resample('W-Fri', how=ohlc_dict)

これにより、金曜日で終わる週の ohlc データが得られます。

于 2013-02-09T02:52:44.123 に答える