LoginSignup
0
2

More than 5 years have passed since last update.

メモ:DataFrame で複雑な条件で抽出する方法

Posted at

単純な条件なら

df = df.query('A > 0 and B > 0')
# もしくは
df = df[df.A > A & df.B > 0]

のように抽出可能なのだが、ブロードキャストができないような、もっと複雑な条件の場合、
たとえば「A列(str)の後ろから4文字目が "8" である行」 だけ抽出する場合は次のように書く。

df = df[df.A.map(lambda x: x[-4] == '4')]
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2