Python 如何获取重采样数据帧中每个时间帧中的最后一个元素?

Python 如何获取重采样数据帧中每个时间帧中的最后一个元素?,python,pandas,Python,Pandas,因此,我将一个bid和ask.csv文件重新采样到一个ohlc数据集中 csv_file = pnd.read_csv("./data/APPL.csv", sep=',', header=True, names=['DateTime', 'Bid', 'Ask'], index_col='DateTime', date_parser=parse, parse_dates={'DateTime'},) 将其添加到数据帧中: df = pnd.DataFrame(csv_file) 然后重新

因此,我将一个bid和ask
.csv
文件重新采样到一个
ohlc
数据集中

csv_file = pnd.read_csv("./data/APPL.csv", sep=',', header=True, names=['DateTime', 'Bid', 'Ask'],  index_col='DateTime', date_parser=parse, parse_dates={'DateTime'},)
将其添加到
数据帧中

df = pnd.DataFrame(csv_file)
然后重新取样,比如:

ohlc_data = df.resample('15Min', how={'Bid':'ohlc'})
现在,我想访问每个条中的最后一个元素,或者说
ohlc
数据集

例如,我想访问在此
ohlc
栏中重新采样的最后一个元素

2016-03-13 00:00:00  1.11384  1.11757  1.11354  1.11651

这是重新采样的
数据框中的一行,如何知道该行原始数据的最后一个元素?

假设“last”项是特定日期
关闭
列中的值,您可以使用
.iloc[]
进行基于整数的访问,或者使用
.loc[]
进行基于时间的查询

一些样本数据:

df = pd.DataFrame(data={'price': np.random.random(1000)}, index=pd.date_range(start=datetime.now(), freq='Min', periods=1000))

resampled = df.resample('15Min').ohlc() # new resample syntax in version 0.18
resampled.tail()
                        price                              
                         open      high       low     close
2016-05-15 03:15:00  0.459310  0.929793  0.054702  0.750257
2016-05-15 03:30:00  0.240577  0.946072  0.051050  0.387052
2016-05-15 03:45:00  0.827814  0.860241  0.083638  0.658283
2016-05-15 04:00:00  0.507453  0.982945  0.100041  0.705432
2016-05-15 04:15:00  0.970364  0.970364  0.102864  0.859491

resampled.iloc[-1, 3]

0.85949050966

resampled.loc['2016-05-15 04:15:00', ('price', 'close')]

0.85949050966

如果您能提供数据示例,那就太好了。