write csv in python based on sub-string condition
<p>I have the following <code>result</code> variable in a data frame (<code>df</code>) and I am trying to output a csv file for those that starts with "test"</p>

<pre><code>abandoned
static
test_a_1
test_b_2
abandoned
test_b_3
</code></pre>

<p>The following code is not working. Thanks in advance for your insights</p>

<pre><code>substr="test"
if substr in df['result']:
    df.to_csv("C:/Projects/result.csv",sep=',',index=False)
</code></pre>

<p>This would work :</p>

<pre><code>df['temp'] = [1 if 'test' in df['result'][k] for k in df.index else 0]
df['result'][df['temp']==1].to_csv("/your/path", sep=',', index=False)
</code></pre>

python string csv substring