Python reading and writing a csv file working with dates
<p>I would like to see in python, the code that reads a csv file containing  years of historical dates with a value (example of each line: 2016-09-23,2173.290039) , this code would then write another csv file with every date and its associated value that occurs on a Friday.  Thank you so much for your help.</p>

<p>The following script will do what you need:</p>

<pre><code>from datetime import datetime   
import csv

with open('input.csv', 'rb') as f_input, open('output.csv', 'wb') as f_output:
    csv_input = csv.reader(f_input)
    csv_output = csv.writer(f_output)

    for row in csv_input:
        if datetime.strptime(row[0], "%Y-%m-%d").weekday() == 4:       # if Friday
            csv_output.writerow(row)
</code></pre>

<p>If <code>input.csv</code> contains:</p>

<pre><code>2016-09-23,2173.290039
2016-09-24,2174.290039
2016-09-25,2175.290039
2016-09-26,2176.290039
</code></pre>

<p>It will create <code>output.csv</code> containing:</p>

<pre><code>2016-09-23,2173.290039  
</code></pre>

python csv calendar