Seeking guidance on vectorized solutions to create Django model objects from a pandas DataFrame with one per row.
I've looked for similar questions and associated answers.
I found https://stackoverflow.com/a/34431482/2193381 but don't want to hardcode the database URL, etc. and am looking for other solutions.
The best I can come up with still uses .apply
and looks like:
def qux(row):
return MyDjangoModel(
foo=row['foo'],
bar=row['bar']
)
data['obj'] = data.apply(qux, axis=1)
MyDjangoModel.objects.bulk_create(
list(data['obj']),
ignore_conflicts=True
)
Is there a better way?