Unable to subset Pandas dataframe
<p>I have the following data in a data frame named <code>in_file</code>:</p>

<pre><code>Client  Value_01   Value_02   Date
ABC     100       500       2016-09-01T
ABC     14        90        2016-09-02T
DEF     95        1000      2016-09-01T
DEF     200       600       2016-09-02T
GHI     75        19        2016-09-01T
GHI     300       700       2016-09-02T
JKL     50        02        2016-09-01T
JKL     400       800       2016-09-02T
</code></pre>

<p>I subset the data frame with the following (which we'll call 'subset 1'):</p>

<pre><code>df_01 = in_file.loc[(in_file.Date == '2016-09-01T') &amp; (in_file.Client &lt;&gt; 'ABC') &amp; (in_file.Client &lt;&gt; 'DEF')].sort_values('Value_01', ascending=False)
</code></pre>

<p>and I get back:</p>

<pre><code>Client  Value_01   Value_02   Date
GHI     75        19        2016-09-01T
JKL     50        02        2016-09-01T
</code></pre>

<p>Then, I attempt to subset the data frame with the following (which we'll call 'subset 2'):</p>

<pre><code>df_02 = in_file.loc[(in_file.Date == '2016-09-01T') &amp; (in_file.Client == 'ABC') &amp; (in_file.Client == 'DEF')].sort_values('Value_01', ascending=False)
</code></pre>

<p>With 'subset 2', I get back an <strong>empty data frame</strong>.  But, I was expecting to see the following:</p>

<pre><code>Client  Value_01   Value_02   Date
ABC     100       500       2016-09-01T
DEF     95        1000      2016-09-01T
</code></pre>

<p>Does anyone know why the 'subset 2' code is not returning the data frame that I expect?</p>

<p>Thanks in advance.</p>

<p>You have two conflicting conditions for your second subset dataframe</p>

<p><code>(in_file.Client == 'ABC')</code> &amp; <code>(in_file.Client == 'DEF')</code></p>

<p>Can never both be true at the same time. </p>

<p>What you seem to be looking for is 'or' logic not '&amp;' logic. So </p>

<p><code>df_02 = in_file.loc[(in_file.Date == '2016-09-02T') or (in_file.Client == 'ABC') or (in_file.Client == 'DEF')].sort_values('Value_01', ascending=False)</code></p>

<p>will give you</p>

<pre><code>ABC     100       500       2016-09-01T
ABC     14        90        2016-09-02T
DEF     95        1000      2016-09-01T
DEF     200       600       2016-09-02T
GHI     300       700       2016-09-02T
JKL     400       800       2016-09-02T
</code></pre>

python pandas subset