我是熊貓新手。我有我想要按日期排序,並計算每個ID,並在一個日期內的日期和時間返回以下數據(股票價格)用python對熊貓進行多字段索引
id,date,time,price
0,2015-01-01,9:00,21.72
1,2015-01-01,9:00,17.65
2,2015-01-01,9:00,54.24
0,2015-01-01,11:00,21.82
1,2015-01-01,11:00,18.65
2,2015-01-01,11:00,52.24
0,2015-01-02,9:00,21.02
1,2015-01-02,9:00,19.01
2,2015-01-02,9:00,50.21
0,2015-01-02,11:00,20.61
1,2015-01-02,11:00,18.70
2,2015-01-02,11:00,51.21
...
...
。我想這
import pandas as pd
import numpy as np
df = pd.read_csv("/path/to/csv", index_col=[0,2,1])
df['returns'] = df['price'].pct_change()
然而,回報是在它們出現的順序在整個IDS計算。任何想法如何正確地做到這一點?我也想訪問數據爲
price_0 = df['id'==0]['date'=='2014-01-01'][time=='9:00']['price']
你應該指明你期待的輸出? –