From 25981b6312dfda98a3d609afb60b0aba2da87679 Mon Sep 17 00:00:00 2001 From: warwick Date: Sun, 17 Feb 2019 21:44:22 +0900 Subject: [PATCH] df.query() as an alternative to chained conditions --- tutorials/things_in_pandas.ipynb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tutorials/things_in_pandas.ipynb b/tutorials/things_in_pandas.ipynb index 968d734..f9d8715 100644 --- a/tutorials/things_in_pandas.ipynb +++ b/tutorials/things_in_pandas.ipynb @@ -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'\")" ] }, {