# How to Calculate a Weighted Average in Pandas

You can use the following function to calculate a weighted average in Pandas: def w_avg(df, values, weights): d = df[values] w = df[weights] return (d…

# Pandas: Sort DataFrame by Both Index and Column

You can use the following syntax to sort a pandas DataFrame by both index and column: df = df.sort_values(by = [‘column_name’, ‘index’], ascending = [False,…

# Pandas: How to Sort Columns by Name

You can use the following syntax to quickly sort a pandas DataFrame by column names: df = df[[‘column1’, ‘column4’, ‘column3’, ‘column2’]] The following examples show…

# How to Create a Pairs Plot in Python

A pairs plot is a matrix of scatterplots that lets you understand the pairwise relationship between different variables in a dataset. The easiest way to…

# How to Find a Confidence Interval for a Median (Step-by-Step)

We can use the following formula to calculate the upper and lower bounds of a confidence interval for a population median: j: nq  –  z√nq(1-q)…

# Format Pivot Tables in Google Sheets (Step-by-Step)

Pivot tables offer an easy way to summarize the values of a dataset. This tutorial provides a step-by-step example of how to create and format…

# Google Sheets Query: How to Create a Pivot Table

You can use the following syntax to create a pivot table using Google Sheets Query: =query(A1:C13, “select A, sum(C) group by A pivot B”) In…

# Google Sheets Query: How to Use Group By

You can use the following syntax to group and aggregate data in a Google Sheets Query: =query(A1:D12, “select B, avg(D) group by B”, 1) In…

# Google Sheets Query: How to Use Order By

You can use the following syntax to order the results of a Google Sheets Query by a certain column: =query(A1:C12, “select A, B order by…

# Google Sheets: A Simple Formula for “If Contains”

You can use the following formula in Google Sheets to determine if a cell contains a certain string: =IF(REGEXMATCH(B1, “this”), 1, 0) In this example,…