Posts

Showing posts from November, 2022

Recode with np.select

Image
Goal: Create a new column based on data from another column. Use Pandas.DataFrame and Numpy.select to create the new column.  You can see the full program at  Google Colaboratory There are three basic steps to accomplish the goal.   Define the conditions Define the values Use np.select to apply the conditions and values. First, create a list containing each "condition," then  create a list containing each return v alue.   The goal is to correlate each condition with each value.  What does that mean?  It means if the first condition in the "conditions" list evaluates as True, return the first value in the "values" list.   An error will occur when the lists have different index counts.  For example, if there are five conditions and 4 values.      This condition example below has two useful applications we would be remiss if we didn't take note:   The first is the use of .isnull() == True. The second is the use of .mean().  The .isnull() == True tells pyt

Python Topic Roadmap

The purpose of this space is to teach and learn.  So, each topic below is covered in a blog post with a Google Colab designed to demonstrate each topic. If a link is not provided, it is on the discovery roadmap. General schedule:     Saturday-Monday research a new topic. Tuesday through Thursday, write code and think about how to approach the problem and solution.  The overall goal is knowledge gap reduction.  What additional tasks can I demonstrate that will reduce my knowledge gap while helping others?  Then, Friday/Saturday, publish a new blog with a quick narration detailing the steps.  Of course, life tends to happen.  So, this schedule is more of a goal than a work schedule.   There is a pattern I use when analyzing data import packages define global variables import data clean data analyze data export results Import Data     pd.read_csv Exploratory Data Analysis (EDA)     pd.describe and pandas-profiling           ( blog via Google Blogger ) Cleaning/Preparing Data for Reporting