CSV file unread columns
<p>l m trying to get data from CSV file and there are three column ("date",stations","pcp" ) including 41 years data set. l would like to get these data separately.</p>

<p>example dataset:</p>

<pre><code>  date      stations     pcp
1.01.1979   6   1.071
2.01.1979   6   5.909
3.01.1979   6   9.134
1.01.1979   5   1.229
2.01.1979   5   0.014
3.01.1979   5   3.241
</code></pre>

<p>when l run code , l got this output</p>

<pre><code>date;stations;pcp None None
2.04.1979;6;0.0 None None
3.04.1979;6;0.0 None None
4.04.1979;6;0.35 None None
5.04.1979;5;0.003 None None
</code></pre>

<p>date field including all data but stations and pcp fields are "None"
how can l solve it?</p>

<p>here is my code</p>

<pre><code>import csv
import numpy as np

with open('p2.csv') as csvfile:
    reader = csv.DictReader(csvfile,fieldnames=("date","stations","pcp"),delimiter=' ', quotechar='|')
    for row in reader:
       print(row["date"],row["stations"],row["pcp"])
</code></pre>

<p>Your input file (<code>p2.csv</code>):</p>

<pre><code>date stations pcp
1.01.1979 6 1.071
2.01.1979 6 5.909
3.01.1979 6 9.134
1.01.1979 5 1.229
2.01.1979 5 0.014
3.01.1979 5 3.241
</code></pre>

<p>Your code:</p>

<pre><code>import csv
import numpy as np

with open('p2.csv') as csvfile:
    reader = csv.DictReader(csvfile,fieldnames=("date","stations","pcp"),delimiter=' ', quotechar='|')
    for row in reader:
       print(row["date"],row["stations"],row["pcp"])
</code></pre>

<p>Output:</p>

<pre><code>date stations pcp
1.01.1979 6 1.071
2.01.1979 6 5.909
3.01.1979 6 9.134
1.01.1979 5 1.229
2.01.1979 5 0.014
3.01.1979 5 3.241
</code></pre>

<p>There is a serious problem with your input file. The delimter is not a single space, it's having multiple spaces. </p>

python csv