2016-08-19 66 views
1

我有这样一个数据帧:梳理数据帧,其中指数满足一定条件

  name pe  outstanding totals  totalAssets 
code                  
300533 abc  30.04  2500.00 10000.00  82066.80 
300532 def  31.27  2100.00 8400.00  77945.25 
603986 NiT  23.40  2500.00 10000.00  89517.36 
600187 ITG  0.00 145562.42 145562.42 393065.88 
000652 IGE  929.15 146567.31 147557.39 2969607.50 

欲梳理的那些行,其第一索引ISIN的3个字符([“000”,“300”] )

其结果将是:

  name pe  outstanding totals  totalAssets 
code                  
300533 abc  30.04  2500.00 10000.00  82066.80 
300532 def  31.27  2100.00 8400.00  77945.25  
000652 IGE  929.15 146567.31 147557.39 2969607.50 

感谢。

+0

'DF [DF [ '代码'] str.startswith( '000')| df ['code']。str.startswith('300')]'会给你带来很大的帮助。 – Evert

回答

2

可以使用str到前3个字符从索引中提取:

df[df.index.str[:3].isin(['300', '000'])] 

#  name  pe outstanding totals totalAssets 
# code     
#300533 abc 30.04  2500.00 10000.00  82066.80 
#300532 def 31.27  2100.00 8400.00  77945.25 
#000652 IGE 929.15  146567.31 147557.39  2969607.50