In this tutorial, we will learn how to convert two columns from dataframe into a dictionary. As the picture below shows the goal is to use one of the column values as keys to dictionary and the second column values as values. Note that this is different from creating a dictionary with column name as […]
How to Replace Multiple Column Values with Dictionary in Python
Sometimes you might like to change the content of Pandas dataframe, values in one or more columns (not the names of the columns) with some specific values. Pandas’ replace() function is a versatile function to replace the content of a Pandas data frame. First, we will see how to replace multiple column values in a […]
How To Save Sparse Matrix in Python to Mtx and Npz file
Sparse matrices in Python are of great of use when you work with dataset that are of high dimensional and sparse. Python’s Scipy has a set of tools to work with different types of commonly used sparse matrices. In this post, we will learn how to save a sparse matrix in Mtx format and npz […]
How to Convert a NumPy Array to Pandas Dataframe
NumPy and Pandas are two most useful python toolkits for data analysis. Sometimes you might want to convert a 2d-array in numpy to a dataframe. In this short tutorial, we will learn how to convert a numpy array into Pandas dataframe. Let us first create some numpy array. We will use NumPy’s random module to […]
How To Categorize Multiple Numerical Columns in R
Recently I had to convert a numerical matrix into categorical ones based on some conditions. Obviously there are multiple ways to go about. One of the key functions to categorize a numerical vector in R is to use cut() function, that allows to specify the intervals to categorize a numerical variable. Till now I was […]