How to create filtered DataFrame with minimum code
<p>There are four cars: <code>bmw</code>, <code>geo</code>, <code>vw</code> and <code>porsche</code>:</p>

<pre><code>import pandas as pd
df = pd.DataFrame({
    'car':      ['bmw','geo','vw','porsche'],
    'warranty': ['yes','yes','yes','no'], 
    'dvd':      ['yes','yes','no','yes'], 
    'sunroof':  ['yes','no','no','no']})
</code></pre>

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

<p>I would like to create a filtered DataFrame that lists only those cars that have all three features presented: the DVD player, the sunroof and a warranty (we know it is BMW here that has all features set to 'yes').</p>

<p>I can do one column at time with:</p>

<pre><code>cars_with_warranty = df['car'][df['warranty']=='yes']
print(cars_with_warranty)
</code></pre>

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

<p>Then I need to do a similar column calculation for dvd and sunroof columns:</p>

<pre><code>cars_with_dvd = df['car'][df['dvd']=='yes']
cars_with_sunroof = df['car'][df['sunroof']=='yes']
</code></pre>

<p>I wonder if there is a clever way of creating the filtered <code>DataFrame</code>?</p>

<h3>EDITED LATER:</h3>

<p>The posted solution works well. But the resulting <code>cars_with_all_three</code> is a simple list variable. We need the DataFrame object with a single 'bmw' car as its the only row and all three columns in place: dvd, sunroof and warranty (with all three values set to 'yes').</p>

<pre><code>cars_with_all_three = []
for ind, car in enumerate(df['car']):
    if df['dvd'][ind] == df['warranty'][ind] == df['sunroof'][ind] == 'yes':
        cars_with_all_three.append(car)
</code></pre>

<p>You can use simple for <code>loop</code> with <code>enumerate</code>:</p>

<pre><code>cars_with_all_three = []
for ind, car in enumerate(df['car']):
    if df['dvd'][ind] == df['warranty'][ind] == df['sunroof'][ind] == 'yes':
        cars_with_all_three.append(car)
</code></pre>

<p>If you do <code>print(cars_with_all_three)</code> you will get <code>['bmw']</code>.</p>

<p>Or, if you want to get really clever and use one-liner, you can do this:</p>

<pre><code>[car for ind, car in enumerate(df['car']) if df['dvd'][ind] == df['warranty'][ind] == df['sunroof'][ind] == 'yes']
</code></pre>

<p>Hope it helps</p>

python pandas indexing dataframe condition