Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. from django.db import models
  2.  
  3.  
  4. class Person(models.Model):
  5. playerID = models.TextField()
  6. birthYear = models.IntegerField()
  7. birthMonth = models.IntegerField()
  8. birthDay = models.IntegerField()
  9. birthCountry = models.TextField()
  10. birthState = models.TextField()
  11. birthCity = models.TextField()
  12. deathYear = models.IntegerField()
  13. deathMonth = models.IntegerField()
  14. deathDay = models.IntegerField()
  15. deathCountry = models.TextField()
  16. deathState = models.TextField()
  17. deathCity = models.TextField()
  18. nameFirst = models.TextField()
  19. nameLast = models.TextField()
  20. nameGiven = models.TextField()
  21. weight = models.IntegerField()
  22. height = models.IntegerField()
  23. bats = models.TextField()
  24. throws = models.TextField()
  25. debut = models.DateField()
  26. finalGame = models.DateField()
  27. retroID = models.TextField()
  28. bbrefID = models.TextField()
  29.  
  30. import pandas as pd
  31. from api.models import Person
  32.  
  33. people_csv = pd.read_csv('data/People.csv')
  34.  
  35. people_objects = []
  36. for p in people_csv.iterrows():
  37. person = Person()
  38. person.playerID = p.playerID
  39. person.birthYear = p.birthYear
  40. person.birthMonth = p.birthMonth
  41. person.birthDay = p.birthDay
  42. person.birthCountry = p.birthCountry
  43. person.birthState = p.birthState
  44. person.birthCity = p.birthCity
  45. person.deathYear = p.deathYear
  46. person.deathMonth = p.deathMonth
  47. person.deathDay = p.deathDay
  48. person.deathCountry = p.deathCountry
  49. person.deathState = p.deathState
  50. person.deathCity = p.deathCity
  51. person.nameFirst = p.nameFirst
  52. person.nameLast = p.nameLast
  53. person.nameGiven = p.nameGiven
  54. person.weight = p.weight
  55. person.height = p.height
  56. person.bats = p.bats
  57. person.throws = p.throws
  58. person.debut = p.debut
  59. person.finalGame = p.finalGame
  60. person.retroID = p.retroID
  61. person.bbrefID = p.bbrefID
  62. people_objects.append(p)
  63.  
  64. Person.objects.bulk_create(people_objects)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement