Sometimes you would like to collapse least frequent values of a factor or character variable in to a new category “Other”. In R forcats library has a suit of functions for lumping the variables. This post contains a Pandas solution that can lump factors or values in three common ways. First, we will see how […]
Pandas 101
How to Change the Order of Columns in a Pandas Dataframe
In this tutorial, we will learn how to change the order of columns in Pandas dataframe. We can change the order of the columns in multiple. Here, we will see two ways to change the order of the columns. First, let us load Pandas. import pandas as pd We will use gapminder dataset to change […]
Pandas pct_change(): Add Colors to Percent with style
Pandas pct_change() function is a handy function that lets us calculate percent change between two rows or two columns easily. By default, pct_change() function works with adjacent rows and columns, but it can compute percent change for user defined period as well. One of the useful features of Pandas pct_change is to add annotation with […]
Pandas pct_change() to compute percent change across columns/rows
In this tutorial, we will see how to compute percent change for values in each column. Pandas’ pct_change() function will compute percent change for each value in a column when compared to the previous element in the column by default. Another way to think is Computes the percentage change from the immediately previous row Pandas’ […]
Pandas applymap(): Change values of Dataframe
Pandas applymap() is yet another useful function to change the content of a dataframe. In this tutorial, we will learn how to use Pandas applymap() function to replace multiple column values using a dictionary. Earlier, we saw how to use Pandas replace() function to change the values in multiple columns using dictionary. And then we […]