Create data from django models from .csv file using pandas library

79 views
Skip to first unread message

Mohammad Aqib

unread,
Oct 15, 2018, 7:12:45 AM10/15/18
to django...@googlegroups.com
I have multiple .csv files to create data from django models into a database using python pandas library. Can anyone suggest me how to do perform this task.

import pandas as pd
df = pd.read_csv(RESOURCE_ROOT + '/data_files/102018_core_business.csv')
business_instance, created = Business.objects.get_or_create(business_id=df['id'], business_name=df['name'])

--
Mohd Aqib
Software Engineer
9873141865

ansh srivastav

unread,
Oct 15, 2018, 7:35:12 AM10/15/18
to django...@googlegroups.com
Which database are you referring to?


Mailtrack Sender notified by
Mailtrack 10/15/18, 5:03:59 PM

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOh93neQTfW0CoepiyhQ57ziGDuw4fN0OTV6w-rJ%2BaXo0aUL%2Bg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Mohammad Aqib

unread,
Oct 15, 2018, 7:36:36 AM10/15/18
to django...@googlegroups.com

Gaurav Toshniwal

unread,
Oct 15, 2018, 6:28:51 PM10/15/18
to Django users
import pandas as pd
df = pd.read_csv(RESOURCE_ROOT + '/data_files/102018_core_business.csv')
for index, row in df.iterrows():
   business_instance, created = Business.objects.get_or_create(business_id=row['id'], business_name=row['name'])

Reply all
Reply to author
Forward
0 new messages