2

I´ve benn using data from an excel file that is in my directory in my Python, but now i need to take the same data from google sheet in drive. I have already upload the excel file to google sheets, but I can't find the way to tell my code to take the data from google drive.

This is how I´m refering to my excel file at the moment.

    per = "2020.09"

    namexlsx = ("excel.file."
                   +per+".xlsx")


    df = pd.read_excel(namexlsx)
    num = np.array([df['NUM']])
    canal = np.array([df['CANAL']])
    cluster = np.array([df['CLUSTER']])
    region = np.array([df['REGION']])

Once i have access to the data i define the name of each variable

    datos_marca = dict()
    for marca in range (1,11):
            datos_marca[marca] = 0
        

    datos_marca[1] = np.array([df['one']])
    datos_marca[2] = np.array([df['two']])
    datos_marca[3] = np.array([df['three']])
    datos_marca[4] = np.array([df['four']])
    datos_marca[5] = np.array([df['five']])
    datos_marca[6] = np.array([df['six']])
    datos_marca[7] = np.array([df['seven']])
    datos_marca[8] = np.array([df['eight']])
    datos_marca[9] = np.array([df['nine']])
    datos_marca[10] = np.array([df['ten']])

Then

f = 1
reg1 = 0

                
count1 = -1

suma0 = dict()
suma1 = dict()
suma2 = dict()
suma3 = dict()
for marca in range (1,11):
        for indicador in range (1,38):
                        suma0[marca,indicador] = 0
                        suma1[marca,indicador] = 0
                        suma2[marca,indicador] = 0
                        suma3[marca,indicador] = 0


num_transp = np.transpose(num)
cantidad = len(num_transp)

while (count1 < cantidad - 1):
        count1 = count1 + 1
        if region[0,count1] == opcion_region2:
           for marca in range (1,6):
              if datos_marca[marca][0,count1] == "Sí":
                   for indicador in range (1,38):
                                if datos[marca,indicador][0,count1] > 0:
                                   suma0[marca,indicador] = suma0[marca,indicador] + 1
                                   if datos[marca,indicador][0,count1] <= 4:
                                        suma1[marca,indicador] = suma1[marca,indicador] + 1
                                   if datos[marca,indicador][0,count1] >= 7:
                                        suma2[marca,indicador] = suma2[marca,indicador] + 1
                                        suma3[marca,indicador] = suma3[marca,indicador] + datos[marca,indicador][0,count1]

import matplotlib.pyplot as plt
import numpy as np
from math import pi

    

Joaquin
  • 23
  • 5
  • 2
    Does this answer your question? [How do I access (read, write) Google Sheets spreadsheets with Python?](https://stackoverflow.com/questions/9690138/how-do-i-access-read-write-google-sheets-spreadsheets-with-python) – Stefano Frazzetto Oct 19 '20 at 13:01
  • it may. But it doesn't explain how to use the data i take from the spreadsheet. Just how to read or write. I need to take the data and do some operations in order to then create some graphics when i run the code. – Joaquin Oct 19 '20 at 13:22
  • Could you add an example for the input data you have and the output you would like to produce? – Stefano Frazzetto Oct 19 '20 at 13:39
  • there i hope it helps. – Joaquin Oct 19 '20 at 13:54
  • 2
    When you upload the xlsx you need to convert it to a google sheet then you can follow this, https://developers.google.com/sheets/api/quickstart/python – Linda Lawton - DaImTo Oct 19 '20 at 13:57

0 Answers0