How can my python code take data from an excel file that is in google drive?

Viewed 549

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

    

0 Answers
Related