mirror of
https://github.com/rasbt/python_reference.git
synced 2025-01-18 07:17:06 +00:00
df.query() as an alternative to chained conditions
This commit is contained in:
parent
b0bd985d7e
commit
25981b6312
|
@ -2662,7 +2662,8 @@
|
|||
"source": [
|
||||
"# Selecting only those players that either playing for Arsenal or Chelsea\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": [
|
||||
"# Selecting forwards from Arsenal only\n",
|
||||
"\n",
|
||||
"df[ (df['team'] == 'arsenal') & (df['position'] == 'forward') ]"
|
||||
"# df[ (df['team'] == 'arsenal') & (df['position'] == 'forward') ]\n",
|
||||
"df.query(\"team == 'arsenal' and position == 'forward'\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user