df.query() as an alternative to chained conditions

This commit is contained in:
warwick 2019-02-17 21:44:22 +09:00
parent b0bd985d7e
commit 25981b6312

View File

@ -2662,7 +2662,8 @@
"source": [ "source": [
"# Selecting only those players that either playing for Arsenal or Chelsea\n", "# Selecting only those players that either playing for Arsenal or Chelsea\n",
"\n", "\n",
"df[ (df['team'] == 'arsenal') | (df['team'] == 'chelsea') ]" "# df[ (df['team'] == 'arsenal') | (df['team'] == 'chelsea') ]\n",
"df.query(\"team in ('arsenal','chelsea')\")\n"
] ]
}, },
{ {
@ -2726,7 +2727,8 @@
"source": [ "source": [
"# Selecting forwards from Arsenal only\n", "# Selecting forwards from Arsenal only\n",
"\n", "\n",
"df[ (df['team'] == 'arsenal') & (df['position'] == 'forward') ]" "# df[ (df['team'] == 'arsenal') & (df['position'] == 'forward') ]\n",
"df.query(\"team == 'arsenal' and position == 'forward'\")"
] ]
}, },
{ {