-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigraciones.py
More file actions
executable file
·29 lines (24 loc) · 897 Bytes
/
migraciones.py
File metadata and controls
executable file
·29 lines (24 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import pandas as pd
import os
# Configurar el entorno de Django
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings.production'
import django
django.setup()
from clientes.models import Cliente
# Leer el archivo CSV
df = pd.read_csv('./data.csv')
df.fillna(value=0, inplace=True)
# Iterar a través de las filas del archivo CSV
for index, row in df.iterrows():
# Crear y guardar un objeto Cliente
obj = Cliente(nombre_orgnanizacion=row['NOMBRE_EDIFICIO'],
direccion=row[df.columns[2]],
apartamentos=row['APTOS'],
administrador=row['ADMINISTRADOR'],
telefono=row['NÚMERO CONTACTO'],
correo=row['CORREO ELECTRÓNICO'],
estado=row['ESTADO'],
frecuencia_meses=row['FRECUENCIA']
)
obj.save()
print('Migración de datos completada con éxito!')