2016-11-17 68 views
1

我有以下形式的數據幀:如何通過索引的開始來過濾熊貓數據框?

code note  
OH2014 Oats Futures, March 2014, OH2014, CBOT 
HGG2004 Copper Futures, February 2004, HGG2004, COMEX 
BRH2014 Brazilian Real (BRL/USD) Futures, March 2014, ... 
F5H2014 PJM PPL Zone Off-Peak Calendar-Month Day-Ahead... 
PDMU2016 MISO Indiana Hub Day-Ahead Peak Calendar-Month... 
GLG2015 Columbia Gulf Louisiana Natural Gas (Platts IF... 
SSIZ2014 Coal (API 8) cfr South China (Argus/McCloskey)... 
KCU1997 Coffee Futures, September 1997, KCU1997, ICE 
FVH2003 5 Year Treasury Note Futures, March 2003, FVH2... 
BOK1974 Soybean Oil Futures, May 1974, BOK1974, CBOT 

其中的代碼是一個指數。

如何過濾只返回代碼以'OH'開始的條目?

回答

1

事情是這樣的:

df[df.index.str.startswith('OH')]