Python Data Science Tutorial #17 - Pandas Queries
Key Takeaways
This video tutorial covers querying data out of data frames with Pandas, including reading from CSV files and using conditional statements to filter data.
Full Transcript
what is going on guys welcome to this peyten tutorial series for data science in today's episode we're going to learn how to query data out of data frames because as we already mentioned data frames are very similar to SQL tables in an SQL you can just query data out off the tables of the database and we're going to do the same thing in pandas today with data frames and also we're going to take a look at how to read from CSV files into data frames so let us get into the code so we start by importing pandas as PD no surprise here and today we're not going to create our dictionary and then transform it into a data frame what we're going to do is we're going to create a CSV file and then import that CSV file into pandas so I'm going to click here a right-click and say new file and just name it people dot CSV and here we're just going to provide SSN and we're going to separate all things by commas so this end then name age and height and I'm going to say okay one Anna H is 45 height is 167 then to John 65 years old yeah they're always changing their social security number their height or age everything just a name stays the same [Music] 188 five could be pop eise forty five also and 178 and last but not least social security number eight Mike and he's 56 or let's make him a little bit younger 26 ah and he's 167 okay we have that budget value already Oh 169 so this is now our CSV file and usually CSV is a very popular format for God for saving data for also uploading data sets so we should know how to deal with that and what we're to do now so I'm just going to say D F equals P D re CSV and providing the people dot CSV file name and we can also specify a delimiter to be a comma of course you don't have to choose comma I can also go ahead and say R or use semicolons or caps is also valid [Music] separator or delimiter and to see if that works we're just going to print a data frame should work doesn't work the limit here the limiter sorry then it should work yeah as conceit works the only thing that we need to do now is to set the index so DF dot set index is the SSN column and in place equals true should work yeah now we have a data set as we know it and as I said today we're going to learn how to query data out of that data set so how can we say give me all the columns that have an H higher than X Y Z or that have a height between this and that because this is what we can do in SQL statements we can say select a name from a data frame where H is greater than 40 for example this would be an SQL statement and we can do the same things here in data frames in a different way of course so what I'm going to say is I'm just going to say print D F dot lock for location so we need to use the lock keyword and in here we're going to open up square brackets and say DF and then we're going to choose the column that we want to query for or that we want to check or make a condition on so I'm going to say give me all the rows the data rows that have an 8 for example that is equal to 45 and when I print that you'll see that we have two entries here with the age 45 and I get Anna and Bob as a result now of course what I can also do is I can just say give me all the ages that are greater than 45 and this would be only John and if I say greater or equal to it would give me John Anna and Bob these two should be yeah of course what I can do is I can also put this into parenthesis here and then just use the ant symbol here and just say okay the H has to be greater or equal to 45 but the height has to also be greater than 170 centimeters so I'm going to say height is greater than 170 and this of course eliminates Anna from this list here because Anna is 167 centimeter size so we only have John and Bob left and now what I can also do is I can just go ahead at the end here and say okay which columns am I even interested in I don't want to know the height and H maybe or anything but the social security numbers so I can just go ahead and say social security number or just give me the name so give me the same results but only give me the names so I get John and Bob now of course the indexes are always part of that because it's the primary key if you want to compare it with SQL structures so that is basically how you query data out off data frames so that's it for this video and I also think that's it for the data science series because now we covered almost everything that you need to know about data science of course if I find some topic that I haven't covered yet that I want to cover in the future I might make some extra episodes but I think that for now we're done with the data science tutorials and we can continue on with the machine learning tutorials so now we're getting into my favorite part of Python programming my favorite field of computer science machine learning and I hope you enjoyed this series I hope you enjoyed this tutorial seer if so hit the like button to support this channel and of course feel free to ask questions and give feedback in the comment section down below and of course subscribe to this channel if you want to see more future videos so thank you very much for watching see you in the next video and bye [Music]
Original Description
In this video we are going to talk about querying data out of data frames with Pandas.
Website: https://www.neuralnine.com/
Instagram: https://www.instagram.com/neuralnine
Twitter: https://twitter.com/neuralnine
GitHub: https://github.com/NeuralNine
Programming Books: https://www.neuralnine.com/books/
Outro Music From: https://www.bensound.com/
Subscribe and Like for more free content!
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from NeuralNine · NeuralNine · 39 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
▶
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
Python Beginner Tutorial #5 - Loops
NeuralNine
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
Python Beginner Tutorial #7 - Functions
NeuralNine
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
Python Beginner Tutorial #9 - File Operations
NeuralNine
Python Beginner Tutorial #10 - String Functions
NeuralNine
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
Python Intermediate Tutorial #6 - Queues
NeuralNine
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
Python Intermediate Tutorial #9 - Recursion
NeuralNine
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
Python Intermediate Tutorial #11 - Logging
NeuralNine
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
Python Machine Learning #4 - Support Vector Machines
NeuralNine
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
Making Text Images Readable Again with Python and OpenCV
NeuralNine
Neural Networks Simply Explained (Theory)
NeuralNine
Motion Filtering with OpenCV in Python
NeuralNine
Top 5 Programming Languages To Learn in 2020
NeuralNine
Simple TCP Chat Room in Python
NeuralNine
Image Classification with Neural Networks in Python
NeuralNine
Edge Detection with OpenCV in Python
NeuralNine
S&P 500 Web Scraping with Python
NeuralNine
Simple Sentiment Text Analysis in Python
NeuralNine
Introduction - Algorithms & Data Structures #1
NeuralNine
Related AI Lessons
⚡
⚡
⚡
⚡
X now offers an MCP server to make its platform easier for AI tools to use
TechCrunch AI
n8n Automation Repurpose Video Content: The 2025 Production Guide
Dev.to AI
You’re Still Paying $200/Month for AI Tools You Could Replace With a Free Local Setup Tonight
Medium · Data Science
Top 10 AI Tools Every College Student Should Know in 2026
Medium · AI
🎓
Tutor Explanation
DeepCamp AI