Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88854

sum an excel file with python

$
0
0

I explain my problem to you I want to recover the sum of each absence of an Excel file for each user :

My code :

The connection to the database :

 con = mysql.connector.connect(user='root', password='mysqladminn',host='intranet.xxxxconsulting.com',database='datab')
        c = con.cursor()



        users = []

        c.execute("SELECT * FROM users")



        #cur.execute("select * from project where id='%s'") % ("daf5dbf6-1e6f-3830-304c-5c0a3316b340")
        fileUsers = open("log.txt", "w")
        for row in c.fetchall():
               fileUsers.write("%s;%s;%s\n" % (row[1],row[5],row[6]))

        fileUsers.close()

Then i open my excel file :

       document1 = xlrd.open_workbook(fichier1)
       feuille_1 = document1.sheet_by_index(0)
       cols = feuille_1.ncols
       rows = feuille_1.nrows

      log = open("log.txt","r") 
        # print(feuille_1.cell_value(rowx=5, colx=3))
        for r in range(6, rows):
            req = "SELECT * FROM users where last_name='"+feuille_1.cell_value(rowx=r, colx=4)+"' and first_name='"+feuille_1.cell_value(rowx=r, colx=5)+"'"
            c.execute(req)
            for row in c.fetchall():
                feuille_1.cell_value(rowx=r, colx=4)+""+feuille_1.cell_value(rowx=r, colx=5)+""+row[1]+""+row[5]+""+row[6]

Now the function to to sum the absences :

      absence = []
      id1 = []
      for row in range(6,361):
                    absence.append(float(feuille_1.cell_value(row, 10).replace(",", ".")))



                result2 = {}
                for name2 in set(id1):
                    result2[name2] = 0


                for i in range(len(id1)):
                   hours2 = absence[i]
                   name2 = id1[i]
                   result2[name2] += hours2

                   print(result2)    

And I want the id1 to represent "row 1" and put all "id1" in one list so that I can finish my code

"row1" correspond at :

syca
syca
rosu
rosu
mami
gale
gale
thgi
heju
almi
saha
saha
saha

My excel file : My excel file


Viewing all articles
Browse latest Browse all 88854

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>