How do I integrate or use SQLModel with Pandas?
See original GitHub issueFirst Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the SQLModel documentation, with the integrated search.
- I already searched in Google “How to X in SQLModel” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to SQLModel but to Pydantic.
- I already checked if it is not related to SQLModel but to SQLAlchemy.
Commit to Help
- I commit to help with one of those options 👆
Example Code
import pandas as pd
jobs_df = pd.read_csv('data/nyc-jobs.csv')
# SQL Model starts from here
Description
I would like to ingest Pandas DataFrame to SQL using the SQLModel. I also would like to retrieve data back using Pandas and SQLModel. Is there a way for it?
Operating System
Linux, Windows
Operating System Details
No response
SQLModel Version
0.0.6
Python Version
3.9
Additional Context
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
SQL for Pythonistas - Python in Plain English
SQLModel, pandas.io.sql) use SQLAlchemy under the hood. Object relational mappers (ORMs) allow to interact with SQL databases using Python classes.
Read more >SQLModel
SQLModel is a library for interacting with SQL databases from Python code, with Python objects. It is designed to be intuitive, easy to...
Read more >Build a REST API with FastAPI and SQLModel - YouTube
Hey guys, In this I walk you through how to build a REST API with FastAPI and SQLModel. SQLModel is a library for...
Read more >SQLModel is the Pydantic inspired Python ORM we ... - YouTube
The first 1000 people to use this link will get a 1 month free trial of Skillshare: https://skl.sh/johnwatsonrooney03221An ORM provides a ...
Read more >GroupBy in SQL & Python: Comparison for Data Analysis | Mode
A GroupBy in Python is performed using the pandas library .groupby() function and a GroupBy in SQL is performed using an SQL GROUP...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Came here for the sqmodel_to_df() function, thank you. I found that the created dataframe does not retain the column order, so here is a slight improvement which does using the first object’s schema attribute.
If you want to convert a DataFrame back to a list of SQLModel objects you could do this.
Not sure how to do this without a loop of some kind. Maybe you could come up with something that uses
pandas.DataFrame.apply()
but I am not sure if that would be faster than the list comprehension in my example.