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 […]
Pandas DataFrame
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 […]
How To Split A Column or Column Names in Pandas and Get Part of it?
Often you may want to create a new variable either from column names of a pandas data frame or from one of the columns of the data frame. Just like Python, Pandas has great string manipulation abilities that lets you manipulate strings easily. Let us see an example of using Pandas to manipulate column names […]