How can l convert tuple to integer to do some calculations?
<p>l have 41 years dataset including 10 columns and l m trying to plot these data with Matplotlib and l m able to plot columns without error. However , l would like to produce different kind of graphes like yearly average pcp ,monthly average pcp and yearly sum of pcp  etc. l got data from columns and l have problem with transforming these data as integer to do some calculations.</p>

<p>here is example dataset from Csv file:</p>

<pre><code>date    day month   year    pcp1    pcp2    pcp3    pcp4    pcp5    pcp6
1.01.1979   1   1   1979    0.431   2.167   9.375   0.431   2.167   9.375
2.01.1979   2   1   1979    1.216   2.583   9.162   1.216   2.583   9.162
3.01.1979   3   1   1979    4.041   9.373   23.169  4.041   9.373   23.169
4.01.1979   4   1   1979    1.799   3.866   8.286   1.799   3.866   8.286
5.01.1979   5   1   1979    0.003   0.051   0.342   0.003   0.051   0.342
6.01.1979   6   1   1979    2.345   3.777   7.483   2.345   3.777   7.483
7.01.1979   7   1   1979    0.017   0.031   0.173   0.017   0.031   0.173
8.01.1979   8   1   1979    5.061   5.189   43.313  5.061   5.189   43.313
</code></pre>

<p>here is my code:</p>

<pre><code>import csv
import numpy as np
import matplotlib.pyplot as plt



with open('output813b.csv', 'r') as csvfile:

    # get number of columns
    for line in csvfile.readlines():
        array = line.split()
        first_item = array[0]

    num_columns = len(array)
    csvfile.seek(0)

    reader = csv.reader(csvfile, delimiter=',')
    next(reader)
    included_col1 = [1]
    included_col6=[4]
    x=[]
    y=[]


    for row in reader:

            content = list(row[i] for i in included_col1)
            content2= list(row[i] for i in included_col6)
            x.append(content)
            y.append(content2)

    klm=tuple(x[i] for i in range(1,1000) if x[i]==["1979"])
    s=0
    for i in range(1,len(klm)):
        s+=y[i] #### error (for +=: 'int' and 'list')

    print (tuple(y[5])) ###example output ('2.345',)
    print (int(y [5][0])) #### error invalid literal for int() with base 10: '2.345'
</code></pre>

<p>tuple in tuple ,l use <code>int(y[5][0])</code> to covert tuple to int but l got an error. l put error messages in my code. how can l fix this problem and l do some calculations. Thanks in advance</p>

<p>You have got 2 different problems:</p>

<p><strong>1. s+=y[i] #### error (for +=: 'int' and 'list')</strong></p>

<p>Here are the relevant part of the code:</p>

<pre><code>y=[]
for row in reader:
        content2= list(row[i] for i in included_col6)
        y.append(content2)
s=0
for i in range(1,len(klm)):
    s+=y[i] #### error (for +=: 'int' and 'list')
</code></pre>

<p>Then:</p>

<ol>
<li><code>s</code> is an <code>int</code></li>
<li><code>y</code> is a list of <code>content2</code></li>
<li><code>content2</code> is a <code>list</code></li>
</ol>

<p>Then you add to an <code>int</code> <code>s</code> a <code>list</code> <code>y[i]</code>.
That is impossible. What do you really want?</p>

<p><strong>2. #### error invalid literal for int() with base 10: '2.345'</strong></p>

<p>You are trying to convert a decimal number into an int.</p>

<p>You should either keep the float number with <code>float(tuple(y[5][0]))</code> or convert it to an int with <code>int(float(tuple(y[5][0])))</code></p>

python csv numpy matplotlib