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>If what you mean is that you want to make a csv that only contains the rows for which result starta with 'test', use the following:</p>

<pre><code>df[df.result.str.contains('^test.*')].to_csv("C:/Projects/result.csv",sep=',',index=False)
</code></pre>

python string csv substring