What Is Hypothesis Testing

Definition of Hypothesis Testing Hypothesis Testing is an inferential statistical method using sample data to solve assumptions about population parameters (characteristics that describe a population). For instance, you want to test if people in New York City’s attitudes toward the new iPhone (e.g., iPhone 14) on a 7-point scale (1 = not at all, 7 = like … Read more

How to change column names of Pandas DataFrames

There are 2 methods of changing the column names of Pandas Dataframes. The following shows the basic Python code syntax for changing column names of Pandas Dataframes. Method 1: df.rename(columns={‘old_name_1′:’new_name_1’, ‘old_name_2′:’new_name_2’}, inplace=True) Method 2: df = df.rename({‘old_name_1′:’new_name_1’, ‘old_name_2′:’new_name_2’}, axis=1) Example 1 of changing column names of Pandas DataFrames (Method 1) The following is the first … Read more

Combine Lists into an Array in Python

You can use Numpy column_stack() or row_stack() to combine lists into an array. As Columns: np.column_stack((list1, list2,…)) As Rows: np.row_stack((list1, list2,…)) Example 1 of lists to columns The following combines lists into an array using column_stack(). Thus, lists become columns in the array. [[6 2 4] [2 1 1] [3 3 2] [4 4 4] … Read more

Check if an item in a Python list

This tutorial shows examples of checking if an item is in a Python list. Method 1: item in list_name Method 2: list_name.index(item) Method 3: list_name.count(item) Example for method 1: Check if an item in a list The following code checks if the item of number 6 is in a list. The following is the output, … Read more

Count the Number of NaN in Pandas Dataframes

This tutorial uses 2 examples to show how to count the number of NaN in Pandas dataframes. Method 1: count the number of NaN by columns: df.isnull().sum() Method 2: count the number of NaN in the whole dataframe: df.isnull().sum().sum() Example for Method 1 The following counts the number of NaN by columns using df.isnull().sum(). The … Read more

How to Subset Rows in Pandas Dataframes

There are at least 4 methods to subset row in Pandas dataframes. Method 1: loc[[Comma]] df.loc[[row_number1, row_number_2]] Method 2: loc[Colon] df.loc[row_number1: row_number_2] Method 3: iloc[[Comma]] df.iloc[[row_number1, row_number_2]] Method 4: iloc[Colon] df.iloc[[row_number1: row_number_2]] Example 1 for Method 1 The following uses loc[[Comma]] (i.e., loc[[0,2]])to subset rows in a Pandas dataframe. The following shows the original dataframe … Read more

Check if Any Value is NaN in a DataFrame

You can check if any value is NaN in a dataframe in Pandas in Python by using the following 2 methods. Method 1: check if any value is NaN by columns: df.isnull().any() Method 2: Check if any value is NaN in the whole dataframe: df.isnull().any().any() Example for Method 1 The following checks if any value … Read more

How to Replace NaN with Blank/Empty Cells in Pandas

You can replace NaN with Blank/Empty cells using either fillna() or replace() in Python. Single Column: Method 1: df[‘Column_name’].fillna(‘ ‘) Method 2: df[‘Column_name’].replace(np.nan,’ ‘, regex=True) Whole dataframe: Method 1: df.fillna(‘ ‘) Method 2: df.replace(np.nan, ‘ ‘, regex=True) Example 1: single column The following uses fillna() to replace NaN with empty cells in a single column. The updated dataframe has … Read more

Difference between NumPy Random and Python Random

NumPy Random is from NumPy, whereas Python Random is a module in Python. That is, Python random is NOT part of NumPy. This tutorial uses two examples to show the difference between NumPy Random and Python Random. Example 1 Python Random’s randint only has parameters of the range, whereas NumPy random’s randint has the additional … Read more

Examples of random.seed( ) in Python

random.seed() function can help save the state of random functions. Thus, by using seed(), these random functions can generate the same numbers on multiple code executions. Example 1 Example 1 shows how to use random.seed() and how it impacts the generated numbers. Note that, random.random() generates a floating point number in the range 0.0 <= X < 1.0. The following … Read more