Skip to content

Instantly share code, notes, and snippets.

@AlejandroVelasco
Last active February 14, 2024 22:37
Show Gist options
  • Select an option

  • Save AlejandroVelasco/b57224f4ff486e93173777ecb92b56d9 to your computer and use it in GitHub Desktop.

Select an option

Save AlejandroVelasco/b57224f4ff486e93173777ecb92b56d9 to your computer and use it in GitHub Desktop.
import pandas as pd
ruta_archivo = r"Punto_nuevo_CRM.xlsx"
nombre_hoja = "Result 1"
def extraer_data(nombre_hoja):
df = pd.read_excel(ruta_archivo, sheet_name=nombre_hoja)
return df
def main():
with open('output.csv', 'w') as f:
print('INICIO DE PROCESO')
print('_______________________________________________________')
df = extraer_data(nombre_hoja)
deptos = df['depto'].unique()
deptos = [d for d in deptos if d not in ('Guatemala', 'Nicaragua', 'Costa Rica', 'Honduras')]
years = df['dm_y'].unique()
results = {
f'{key}': {
f'{depto}': None
for depto in deptos
}
for key in years
}
for index, row in df.iterrows():
if row['dm_m'] == 1 and row['categoria'] in ('PYME', 'Internet') and 'internet' in row['producto'].lower():
year = str(row['dm_y'])
depto = row['depto']
if results[year][depto] is not None:
if row['Mensual'] > results[year][depto]['Mensual']:
results[year][depto] = row
elif row['Mensual'] == results[year][depto]['Mensual'] and row['velocidad'] > results[year][depto]['velocidad']:
results[year][depto] = row
else:
results[year][depto] = row
# print(results)
for year in results:
for depto in results[year]:
if results[year][depto] is not None:
line = results[year][depto]
f.write(f"{year},{depto},{line['Mensual']},{line['velocidad']}\n")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment