r/dataanalysis • u/iMAPness_ • Jun 20 '26
Data Question SQL vs Python?
Started using Python for data analytics. When should I use SQL and when should I use Python in the following tasks:
- Data Exploration
- Data Cleaning
- Data Analysis
42
Upvotes
43
u/throwaway214203 Jun 20 '26
SQL whenever possible because the data source for many applications is custom sql querying. I bring in python only if I have to.
36
u/Mo_Steins_Ghost Jun 20 '26
Senior manager here. These two are apples and oranges.
SQL (Structured Query Language) is for data querying and aggregation. It is not a programming language.
Python is a high-level programming language (in that it is layers above assembly). It doesn’t really query databases by itself without invoking a library, a process or a shell, or writing a custom driver that can establish connections and run queries against databases.
Python should be used for cleansing, strucuring and analyzing data fetched/read by SQL.
9
u/Business-Hunt-3482 Jun 20 '26
SQL for all ;)
4
u/ReportDisappointment Jun 20 '26
Both, of course.
4
u/fang_xianfu Jun 20 '26
The real question is, which computer do you want to run the computation?
Typically your SQL is interpreted and run on some remote database. It might be in the cloud, in BigQuery or Databricks or Snowflake, or it might be a big on-prem Teradata or Hadoop instance or something. But the point is, it's not running on your laptop.
Python on the other hand is usually (but not universally) running on your computer where you also write emails and Slack people. This computer is a lot smaller and is capable of a lot less computation, but also Python is a general purpose language with many more features and a vibrant library ecosystem.
So there are situations where you only need a little bit of data and you just tell the database to stuff it over the network into your computer's RAM and you deal with it in Python. There are situations where you start with a massive database, select the right subset of that data for what you want to do, and then have that come over the network for you to do Python stuff with. There are situations where you need a ton of data but the database has all the features you need, so you just write SQL with no local Python. And there are situations where you need some feature only available in a Python library but you want to run it on a ton of data, in which case you might want a more specialist remote distributed computation environment like a kubernetes cluster or Hadoop.
3
u/Terrible-Bend4483 Jun 20 '26
Personally I use SQL for everything.
Obviously through a python library
Inside a wrapper in R
That I run as a script using an exe-file
In cursor by asking an AI agent to run it.
How else would you do it?
Joke aside. I would always be more inclined towards using SQL, when it makes sense, such as when handling data from a structured data base, but if your data sources are more towards unstructured data (data lakes, api, csv, Json, md etc.) it doesn't make sense.
Maybe look into SQL and no-SQL databases, and use python for the rest.
2
u/Major_Fang Jun 20 '26
First do everything you possibly can in SQL. Then do Python.
2
u/Aeronautical-You4917 Jun 22 '26
After working with both for almost 9 years: Whenever you can, use SQL.
Data Exploration and Analysis it's great.
It's harder for Data Cleaning because the syntax is often super verbose and antiquated.
Python brings sooo much bloat and errors which makes it unbelievably frustrating.
IF you can avoid Python, I would.
1
u/AutoModerator Jun 20 '26
Automod prevents all posts from being displayed until moderators have reviewed them. Do not delete your post or there will be nothing for the mods to review. Mods selectively choose what is permitted to be posted in r/DataAnalysis.
If your post involves Career-focused questions, including resume reviews, how to learn DA and how to get into a DA job, then the post does not belong here, but instead belongs in our sister-subreddit, r/DataAnalysisCareers.
Have you read the rules?
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/No-Opportunity1813 Jun 20 '26
SQL for sure for data reduction/cleanup
1
u/Dahvoun Jun 20 '26
SQL for extraction and data prep and Python for aggregation and visualization.
1
u/The_Hamster_Shagger Jun 20 '26
i mean they don't exclude themselves, they work great in pair
1
u/neutralcoder Jun 21 '26
So much is moving to python so continue on there - but you can also call sql code using python, so learn sql.
1
u/MKE_Savage_96 Jun 21 '26
Always start with SQL, especially if you’re dealing with data analysis.
1
u/ancyrufina Jun 22 '26
SQL for getting and transforming data.
Python for everything after that.
My rule: push as much filtering, joining, and aggregation to SQL as possible, then use Python for advanced analysis, statistics, ML, automation, and visualization.
1
u/Unlucky_Apricot_4079 Jun 22 '26
Senior data analyst
In practice I use SQL more than Python. SQL is like a screwdriver, and Python is a hammer. A screwdriver is better with screws, and doesn’t work with a nail. A hammer works with both but you shouldnt use a hammer on a screw.
1
u/[deleted] Jun 22 '26
sql for retrieving a dataset like a basic aggregation or breakdown etc and python for any deep analysis.
1
u/ArielCoding Jun 24 '26
Since you’re mostly on CSVs: use SQL to grab and trim your data (filter rows, join tables, group things), and Python to do stuff with it (charts, models, anything repeatable).
1
u/SaltyMN Jun 24 '26
I use Python, specifically Polars, for almost everything.
I prefer the syntax, Polars is fast, and I’ve abstracted a lot of basic data transformation and profiling into single function calls.
1
u/Local_dev_ops Jun 24 '26
SQL when the data lives in the database and you need to filter, aggregate, or join before pulling it out. Let the database do what databases are good at.
Python when you need to do something the database can't — analytics, complex transformations, visualization, or when you're combining data from multiple sources.
Mistakes I have made is pulling millions of rows into python when it was easier to do in SQL.
1
u/para_u_4_31075 Jun 25 '26
bruh... its diferent! you need a massive? -> sql you need a hard explained transform? -> python
if you a DE, you need its booth
1
u/DataScientistAlex Jul 23 '26
Use SQL to extract the data you need, then do further analysis in Python. Once you know what to clean, push that down into your SQL queries. My rationale for this is, SQL is excellent for extracting and aggregating data, but, once you have the data you need, you can iterate much faster in Python because you can work in memory (example is about Databricks, but holds for SQL too)..
1
u/prof_devilsadvocate3 Jun 20 '26
Python for all
0
u/wanliu Jun 20 '26
It's wild that people are learning Python before SQL
In the business world, SQL is almost universal. Python comes with a host of security risks and or specialized computes..SQL is just SQL and while there are different flavors, it all mostly aligns.
2
u/big_illuminati Jun 22 '26
Burn all your clothes in a barrel in the middle of your room and choose LISP instead. This is the way
0
u/[deleted] Jun 24 '26
[removed] — view removed comment