2016-08-19 69 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