When to Use ddof=1 in np.std()

The following is the rule of using ddof in np.std() in Numpy. Rule 1: If you are calculating standard deviation for a sample, set ddof = 1 in np.std(). np.std(sample_name, ddof=1) Rule 2: If you are calculating standard deviation for a population, set ddof = 0 in np.std(). np.std(population_name, ddof=0) Example of ddof = 1 … Read more

Generate Random Numbers in Python

This tutorial shows how you can use Numpy to generate random numbers in Python. The following is the basic syntax summarizing 3 functions. 1. Integers: np.random.randint() 2. Normal distribution: np.random.randn() 3. Uniform distribution: np.random.rand() Example 1: Integer np.random.randint(low, high=None, size=None, dtype=int) np.random.randint() will return integer numbers. Given that there are quite a few parameters in randint(), it is … Read more

How to Round Numbers in Pandas

You can use round() and apply() to round up and down numbers in Pandas. Round to specific decimal places: df.round(decimals = number of specific decimal places) Round up numbers: df[‘DataFrame column’].apply(np.ceil) Method 3: Round down values: df.apply(np.floor) Data being used The following is a column of numbers that we are going to use in this … Read more

How to Create an Empty Pandas Dataframe

You can use DataFrame() to create an empty Pandas dataframe. The following is the basic syntax as well as two examples. import pandas as pd df = pd.DataFrame() Example 1 The following creates an empty dataframe in Pandas and prints it out. The following is the output. As we can see, both columns and indexes … Read more

How to Replace NaN with Zero in Pandas

You can replace NaN with zero using either fillna(0) in Pandas or replace(np.nan,0) in Numpy. Single Column: Method 1: df[‘Column_name’].fillna(0) Method 2: df[‘Column_name’].replace(np.nan,0) Whole dataframe: Method 1: df.fillna(0) Method 2: df.replace(np.nan,0) Example 1: single column The following Python code first creates a dataframe with NaN in both columns and then replaces NaN in the first … Read more

Quartile: Definition and Example

Definition of Quartile A quartile is a statistic describing how a set of data points are divided into 4 groups. Quartiles split a set of data by using 3 points: the lower quartile (Q1), the median (Q2), and the upper quartile (Q3). Together with the minimum and maximum values, 3 quartiles split the data set … Read more

Difference between Descriptive Statistics and Inferential Statistics

Descriptive statistics aim to summarize the characteristics of a given data set. In contrast, inferential statistics aim to use a sample of data to draw inferences about the whole population (i.e., hypothesis testing). Types of Descriptive Statistics 1. Measures of Central Tendency Central tendency is used to describe where the center of a dataset is located. Mean, … Read more

Difference between Sample and Population

A population is the entire group of individuals about whom you want to draw conclusions. In contrast, a sample is the subset of the same entire group. Example 1 of sample and population You would like to study if students like online courses at your university. Suppose your university has 10K students; thus, these 10K students … Read more

Calculate Population Variance in Excel

You can use the VARP, VAR.P, or VARPA functions in Excel to calculate population variance.  Data Example The following is the data example for population variance. Example of VARP() Type =VARP(B2:B12) in a cell in Excel to calculate population variance. The population variance is 46.23. Example of VAR.P() Type =VAR.P(B2:B12) in a cell in Excel to calculate population variance. The population … Read more

Population Variance Formula and Calculation by Hand

This tutorial shows the formula for population variance and the steps for calculating population variance by hand. Formula Population variance is the measure of the variability of a population. The following is the formula for population variance. where, Population vs. Sample Data The following is the population of a set of data. It has 11 … Read more