Well, I'm working with an open database, and it's in CSV, I'm using DJANGO to read the CSV and thus inserting into the database ... But it's failing to insert the first year, I'm trying to insert 8 years of data, the first year it inserts only 11 months, so it's missing insert 1 month to properly close the data.
from django.shortcuts import render
from models import Internacao
import csv
def csvInternacao(request):
coluna = 1
mes = 1
ano = 2008
while (ano < 2017):
with open('locale', 'rb') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in spamreader:
if row[0] is not None:
t = Internacao()
t.idmunicipios = row[0]
t.quantidade = row[coluna]
t.data = str(ano) + '-' + str(mes) + '-01'
t.save(force_insert=True)
print t.idmunicipios, t.data, t.quantidade
mes = mes + 1
coluna = coluna + 1
print mes
if coluna%12 == 0:
print ano
mes = 1
ano = ano + 1
So by reading each column of the csv and changing the columns automatically and changing the year, because each column is a month. Does anyone know why I can not do the insert correctly?