Python Data Science Tutorial #17 - Pandas Queries

NeuralNine · Beginner ·🛠️ AI Tools & Apps ·6y ago

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 Visualizing Stock Data With Candlestick Charts in Python
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
2 Python Beginner Tutorial #1 - Installation and First Program
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
3 Python Beginner Tutorial #2 - Variables and Data Types
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
4 Python Beginner Tutorial #3 - Operators and User Input
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
5 Python Beginner Tutorial #4 - If Statements and Conditions
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
6 Python Beginner Tutorial #5 - Loops
Python Beginner Tutorial #5 - Loops
NeuralNine
7 Python Beginner Tutorial #6 - Sequences and Collections
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
8 Python Beginner Tutorial #7 - Functions
Python Beginner Tutorial #7 - Functions
NeuralNine
9 Python Beginner Tutorial #8 - Exception Handling
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
10 Python Beginner Tutorial #9 - File Operations
Python Beginner Tutorial #9 - File Operations
NeuralNine
11 Python Beginner Tutorial #10 - String Functions
Python Beginner Tutorial #10 - String Functions
NeuralNine
12 Python Intermediate Tutorial #1 - Classes and Objects
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
13 Python Intermediate Tutorial #2 - Inheritance
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
14 Python Intermediate Tutorial #3 - Multithreading
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
15 Python Intermediate Tutorial #4 - Synchronizing Threads
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
16 Python Intermediate Tutorial #5 - Events and Daemon Threads
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
17 Python Intermediate Tutorial #6 - Queues
Python Intermediate Tutorial #6 - Queues
NeuralNine
18 Python Intermediate Tutorial #7 - Sockets and Network Programming
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
19 Python Intermediate Tutorial #8 - Database Programming
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
20 Python Intermediate Tutorial #9 - Recursion
Python Intermediate Tutorial #9 - Recursion
NeuralNine
21 Python Intermediate Tutorial #10 - XML Processing
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
22 Python Intermediate Tutorial #11 - Logging
Python Intermediate Tutorial #11 - Logging
NeuralNine
23 Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
24 Python Data Science Tutorial #2 - NumPy Arrays
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
25 Python Data Science Tutorial #3 - Numpy Functions
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
26 Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
27 Python Data Science Tutorial #5 - Subplots and Multiple Windows
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
28 Python Data Science Tutorial #6 - Matplotlib Styling
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
29 Python Data Science Tutorial #7 - Bar Charts with Matplotlib
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
30 Python Data Science Tutorial #8 - Pie Charts with Matplotlib
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
31 Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
32 Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
33 Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
34 Python Data Science Tutorial #12 - Pandas Series
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
35 Python Data Science Tutorial #13 - Pandas Data Frames
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
36 Python Data Science Tutorial #14 - Pandas Statistics
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
37 Python Data Science Tutorial #15 - Pandas Sorting and Functions
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
38 Python Data Science Tutorial #16 - Pandas Merging Data Frames
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
Python Data Science Tutorial #17 - Pandas Queries
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
40 Python Machine Learning Tutorial #1 - What is Machine Learning?
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
41 Python Machine Learning Tutorial #2 - Linear Regression
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
42 Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
43 Python Machine Learning #4 - Support Vector Machines
Python Machine Learning #4 - Support Vector Machines
NeuralNine
44 Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
45 Python Machine Learning Tutorial #6 - K-Means Clustering
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
46 Python Machine Learning Tutorial #7 - Neural Networks
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
47 Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
48 Generating Poetic Texts with Recurrent Neural Networks in Python
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
49 Stock Portfolio Visualization with Matplotlib in Python
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
50 Analyzing Coronavirus with Python (COVID-19)
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
51 Making Text Images Readable Again with Python and OpenCV
Making Text Images Readable Again with Python and OpenCV
NeuralNine
52 Neural Networks Simply Explained (Theory)
Neural Networks Simply Explained (Theory)
NeuralNine
53 Motion Filtering with OpenCV in Python
Motion Filtering with OpenCV in Python
NeuralNine
54 Top 5 Programming Languages To Learn in 2020
Top 5 Programming Languages To Learn in 2020
NeuralNine
55 Simple TCP Chat Room in Python
Simple TCP Chat Room in Python
NeuralNine
56 Image Classification with Neural Networks in Python
Image Classification with Neural Networks in Python
NeuralNine
57 Edge Detection with OpenCV in Python
Edge Detection with OpenCV in Python
NeuralNine
58 S&P 500 Web Scraping with Python
S&P 500 Web Scraping with Python
NeuralNine
59 Simple Sentiment Text Analysis in Python
Simple Sentiment Text Analysis in Python
NeuralNine
60 Introduction - Algorithms & Data Structures #1
Introduction - Algorithms & Data Structures #1
NeuralNine

This video tutorial teaches how to query data out of data frames with Pandas, including reading from CSV files and using conditional statements to filter data. The tutorial covers the basics of data manipulation and analysis with Pandas.

Key Takeaways
  1. Import Pandas library
  2. Create a CSV file
  3. Read the CSV file into a data frame
  4. Set the index of the data frame
  5. Use conditional statements to query data from the data frame
  6. Filter data based on conditions
💡 Pandas data frames can be queried using conditional statements, similar to SQL tables.

Related AI Lessons

Up next
I Asked ChatGPT to Apply to 500 Jobs (8 Interviews in 48 Hours)
Sabrina Ramonov 🍄
Watch →