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><strong><em>Caveat</em></strong> This is not the best solution!!!<br>
I only want to point out what you were doing wrong.<br>
@MaxU has the best answer</p>

<p>define <code>cond2</code></p>

<pre><code>cond2 = (in_file.Date == '2016-09-01T') &amp; \
        (in_file.Client == 'ABC') &amp; \
        (in_file.Client == 'DEF')
</code></pre>

<p>This will always be <code>False</code> as <code>in_file.Client</code> can never be both <code>'ABC'</code> and <code>'DEF'</code>.  You must use 'or' <code>|</code></p>

<p>Instead</p>

<pre><code>cond2 = (in_file.Date == '2016-09-01T') &amp; \
        ((in_file.Client == 'ABC') | (in_file.Client == 'DEF'))
</code></pre>

<p>Then</p>

<pre><code>df_02 = in_file.loc[cond2].sort_values('Value_01', ascending=False)
df_02
</code></pre>

<p><a href="http://i.stack.imgur.com/czQvv.png" rel="nofollow"><img src="http://i.stack.imgur.com/czQvv.png" alt="enter image description here"></a></p>

<hr>

<h1>But Don't Choose This Answer</h1>

<p>It is not as good as using <code>isin</code></p>

python pandas subset