Thursday, April 29, 2021

Re: Loading csv data in database

you may use pandas for this 
you can use it as follows:-
first install it
if not using python from anaconda environment!

pip install pandas
import pandas as pd
reader=pd.read_csv("sample-dataset.csv")
reader.head(3) # for viewing top 3 rows.

hope this may help you
 -)-)
On Thursday, 29 April 2021 at 21:43:28 UTC+5:30 mkhaskheli....@seecs.edu.pk 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 load data won't 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]
)

Now, how to run this script?


--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f9a6e8cc-2d34-4641-aa7e-9d4ead0696ben%40googlegroups.com.

No comments:

Post a Comment