Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.db import models
- class Person(models.Model):
- playerID = models.TextField()
- birthYear = models.IntegerField()
- birthMonth = models.IntegerField()
- birthDay = models.IntegerField()
- birthCountry = models.TextField()
- birthState = models.TextField()
- birthCity = models.TextField()
- deathYear = models.IntegerField()
- deathMonth = models.IntegerField()
- deathDay = models.IntegerField()
- deathCountry = models.TextField()
- deathState = models.TextField()
- deathCity = models.TextField()
- nameFirst = models.TextField()
- nameLast = models.TextField()
- nameGiven = models.TextField()
- weight = models.IntegerField()
- height = models.IntegerField()
- bats = models.TextField()
- throws = models.TextField()
- debut = models.DateField()
- finalGame = models.DateField()
- retroID = models.TextField()
- bbrefID = models.TextField()
- import pandas as pd
- from api.models import Person
- people_csv = pd.read_csv('data/People.csv')
- people_objects = []
- for p in people_csv.iterrows():
- person = Person()
- person.playerID = p.playerID
- person.birthYear = p.birthYear
- person.birthMonth = p.birthMonth
- person.birthDay = p.birthDay
- person.birthCountry = p.birthCountry
- person.birthState = p.birthState
- person.birthCity = p.birthCity
- person.deathYear = p.deathYear
- person.deathMonth = p.deathMonth
- person.deathDay = p.deathDay
- person.deathCountry = p.deathCountry
- person.deathState = p.deathState
- person.deathCity = p.deathCity
- person.nameFirst = p.nameFirst
- person.nameLast = p.nameLast
- person.nameGiven = p.nameGiven
- person.weight = p.weight
- person.height = p.height
- person.bats = p.bats
- person.throws = p.throws
- person.debut = p.debut
- person.finalGame = p.finalGame
- person.retroID = p.retroID
- person.bbrefID = p.bbrefID
- people_objects.append(p)
- Person.objects.bulk_create(people_objects)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement