detaframeの任意列と条件を表したタプルからindexing

indexing tuple based on list of names – StackOverflow

import io
import pandas as pd

strings = """index               ticker     asset
0    233740 KS Equity  KOSDQ150
1    233160 KS Equity  KOSDQ150
2    278240 KS Equity  FKSDQ150
3    123760 KS Equity  KOSPI2LG
4    267500 KS Equity   SPUSTBP
405  292120 KS Equity  FNGDMSMI
406  292100 KS Equity  FNGDLGGI
407  292130 KS Equity  FNGDMSGI
408  293180 KS Equity    KOSPI2
409  292150 KS Equity  FNGDTP10
410  292110 KS Equity  FNGDLGVI"""

df = pd.read_csv(io.StringIO(strings), sep='\s{2,}', engine='python').drop('index', axis=1)
leverage = ['233740 KS Equity', '233160 KS Equity', '278240 KS Equity', '123760 KS Equity', '267500 KS Equity', '292340 KS Equity']
df[df['ticker'].isin(leverage)]
    ticker          asset
0   233740 KS Equity    KOSDQ150
1   233160 KS Equity    KOSDQ150
2   278240 KS Equity    FKSDQ150
3   123760 KS Equity    KOSPI2LG
4   267500 KS Equity    SPUSTBP
カテゴリー: 未分類 パーマリンク