top of page
brandynewanek_httpss.mj.run6oi86OdI5YQ_create_Banner_for_Python_f4e2610c-f493-4b04-a4ac-c2

Python Data Basics - Logic Statements, Filtering

In the 2nd free to use Python Data Basics program, we use logic statements to control the flow of our workflow.  In other words, we are able to control which part of our code will be performed on which data.  Logic statements are statements that check whether a value is True or False.  Logic is a simple Python concept but allows flexibility in how our code evolves.

As data scientists, another common use of logic statements is to filter our data.  By this, we mean we are able to filter our data down to only the rows that mean a certain requirement.   

This can work in two ways, we either select only one or certain categories from our dataset and use it to create a subset of data that only contains those rows.  We can also filter on a numeric column getting back only those rows that are greater or less than the value of interest.

The ability to filter our data in Python will be important for our data analysis as often want to understand relationships that apply to a subset of our Data. 

Python Data Basics - Logic Statements, Filtering

Python Logic Operators

Python Logic Operators
python data basics logic statements filtering data

In this section of the free-to-use Python data basics class, we discuss how logic operators work in Python and how we would use Python logical operators in data science and data analysis to select or section the data that we desire for our analysis or filter the data we are putting into our machine learning model.  In Python True values are equal to 1 and False values are equal to 0.  This is a simple concept but fundamental to getting comfortable with coding.

Python Conditional Statements

Python Conditional Statments
python data basics conditional statements simple easy learning python data science

In the easy to use educational material we discuss Python conditional statments and how will will use if and else statements with logic statments to control the flow of how our code evolves.  Controling which code will execute in on which section of data.  If and else Python conditional statements are used in preprocessing techniques to create categories from contiuous variables and in help clean our dirty data.

Filter, Select, Control

free educational independent learning python data basics conditional control statements

In the educational independent learning data material we use logical statements in Python we are able to select only sub sections of our data.  The ability to select only data that mets certain requires is import in many way and eventually with practice this ability to select data will start to feel similar to the ability we have to select data in a spreadsheet using a mouse.  Haing the ability to control our work flow in Python and gives us the ability to control when certain operation in Python will execute.

Logical Indexing

free python logical indexing use python like your mouse educational material learn python

Free data science learning material to independently learn Python.  Logical indexing is different from Python Indexing.  Logical indexing in Python allows us to select only the rows that we interested in analysis.  Logical indexing in a Pandas DataFrame will give control over which section of data were are interested in analyzing.  Logical indexing can also be help in correcting errors or data augmentation only on certain section. Learn data science for free.

Explore Filtering and Logic with free Python Code

dual logical indexing in pandas

Logical indexing in Python is incredibly useful as it allows one to section out data and complete analysis or perform preprocessing techniques only on a subsection of data.  Logical Indexing in Python would allow us to isolate and only analyze people from one gender or from a certain city.  We can also use logical indexing in Pandas to select only those observations that are above or below a set point in a continuous variable.  Going a step further with dual logical indexing we can filter only those observations that met both of those requires using and statement and that meet any requirement using or statement in Python with Pandas.  Follow along with the free to use Python Colab on Logical Statements.

bottom of page