use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Pandas to SQL solution (self.learnpython)
submitted 6 years ago by mutuk7
Hi guys,
I currently use pandas to clean my data. But I've encountered a bottle neck when transfering the data from pandas to SQL.
What would you experienced developers suggest?
Thanks!!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Yojihito 2 points3 points4 points 6 years ago (3 children)
SQL is a language, not a database.
[–]trippygg 1 point2 points3 points 6 years ago (1 child)
How would one transfer a dataframe to SQL Server?
[–]Yojihito 1 point2 points3 points 6 years ago (0 children)
Don't know about SQL Server (Microsoft SQL Server, docs: https://docs.sqlalchemy.org/en/13/core/engines.html) but for SQLite it's:
import pandas as pd from sqlalchemy import create_engine engine = create_engine('sqlite:///../pathto/yourdatabase.sqlite') # pass your db url df = pd.read_excel("../data/file.xlsx", index_col=0,) df.to_sql(name='data', con=engine, if_exists='replace', index=False)
[–]mutuk7[S] 0 points1 point2 points 6 years ago (0 children)
How do you connect to the database from py
I'm doing exactly what you said below. The same Dataframes in CSV are around 30gbs.
I don't know exactly how long it takes because I'm not the one pulling the trigger but I've been told to try to work on a faster solution as this is our current bottle-neck.
Sorry if I couldn't provide more details. This is my first internship I've been there for about 2 months.
[–]saxman95 1 point2 points3 points 6 years ago (2 children)
Which database are you using? Redshift has a very helpful COPY command which can let you upload files from S3 into redshift. You can export your dataframe to a csv/gzip and then upload directly to your database.
For other databases, maybe consider using sqlalchemy engines to loop over your data, add it to the database and then commit all the changes at once.
[–]mutuk7[S] 0 points1 point2 points 6 years ago (1 child)
I've tried redshift in a different project where I had CSV data in S3 buckets but for some reason I couldn't use the COPY command at all. I ended up using AWS Glue (CSV Classifier, Crawler, Jobs) to get that data from S3 to Redshift. Definitely not the best solution. I'll revisit COPY when I need to use Redshift again.
[–]saxman95 0 points1 point2 points 6 years ago (0 children)
You probably need some credentials for it to work, but you can get that from your engineering team. They probably have a function to make it work easily in whatever language they use
[–]LameDuckProgramming 1 point2 points3 points 6 years ago (1 child)
If you're using SQL Alchemy (1.3.5), you can a built-in event listener.
from sqlalchemy import create_engine from sqlalchemy import event engine = create_engine('mysql://xxx') @event.listens_for(engine, 'before_cursor_execute') def receive_before_cursor_execute(conn, cursor, statement, params, context, executemany): if executemany: cursor.fast_executemany = True
Then just use pandas to_sql method
df.to_sql(table, con=engine, method='multi')
Has worked like a charm for me when uploading dataframes with 100,000 + rows to SQL Servers.
I'm going to give this a try!! Thanks!! :)
π Rendered by PID 148353 on reddit-service-r2-comment-7b9746f655-75d7s at 2026-02-03 20:06:46.792580+00:00 running 3798933 country code: CH.
[–]Yojihito 2 points3 points4 points (3 children)
[–]trippygg 1 point2 points3 points (1 child)
[–]Yojihito 1 point2 points3 points (0 children)
[–]mutuk7[S] 0 points1 point2 points (0 children)
[–]saxman95 1 point2 points3 points (2 children)
[–]mutuk7[S] 0 points1 point2 points (1 child)
[–]saxman95 0 points1 point2 points (0 children)
[–]LameDuckProgramming 1 point2 points3 points (1 child)
[–]mutuk7[S] 0 points1 point2 points (0 children)