Often you may have a column in your pandas data frame and you may want to split the column and make it into two columns in the data frame. For example, one of the columns in your data frame is full name and you may want to split into first name and last name (like […]
String Manipulations in Pandas
Python is known for its ability to manipulate strings. Pandas extends Python’s ability to do string manipulations on a data frame by offering a suit of most common string operations that are vectorized and are great for cleaning real world datasets. Let us some simple examples of string manipulations in Pandas Let us use gapminder […]
How to Change Type for One or More Columns in Pandas Dataframe?
Sometimes when you create a data frame, some of the columns may be of mixed type. And you might see warning like this DtypeWarning: Columns (0) have mixed types. Specify dtype option on import or set low_memory=False. We get this error when Pandas tries to guess the type for each element of a column. For […]
How to Collapse Multiple Columns in Pandas? Groupby with Dictionary
Often you may want to collapse two or multiple columns in a Pandas data frame into one column. For example, you may have a data frame with data for each year as columns and you might want to get a new column which summarizes multiple columns. One may need to have flexibility of collapsing columns […]
How To Convert a Column to Row Name/Index in Pandas?
Pandas has a method set_index to covert a column in Pandas dataframe into rowname or row index. Let us see an example of converting a column name into rowname in Pandas. Let us load pandas as “pd”. Let us use real-world gapminder data from vega_datasets. Convert a Column to Row Name Let us convert the […]