To load a csv file in python you use * pd.read_csv('your file', index_col=0) . *
*So you need to use the library pandas.* *Hope it helps.* On Thu, Apr 29, 2021 at 3:23 PM 'Muhammad Asim Khaskheli' via Django developers (Contributions to Django itself) < django-developers@googlegroups.com> wrote: > Hi, > > I wanted to ask how to load csv data into the model. What steps do we have > to follow . > > I have made this function but how exactly to run this code because, python > manage.py loaddata wont work. > > def import_data(): > with open('sample-dataset.csv') as f: > reader = csv.reader(f) > for row in reader: > if row[0] != 'user_id': > _, created = Funnel.objects.get_or_create( > user_id=row[0], > event=row[1], > timestamp=row[2], > session_id=row[3] > ) > > > -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-developers+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/ab4f4d9d-87b6-45e4-b490-1d665b1795can%40googlegroups.com > <https://groups.google.com/d/msgid/django-developers/ab4f4d9d-87b6-45e4-b490-1d665b1795can%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Best Wishes *Mr Tchouanga* -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CANRJ%3D3n5ejYQ0FV888dBsySS8xMLZo4B1-PwEDAis0BDhXdYBw%40mail.gmail.com.