Categorical Data in Pandas

In this lesson, we will learn how to work with Categorical data in Pandas. It is a Pandas data type corresponding to categorical variables in statistics. A categorical variable takes on a limited number of possible values. Examples are gender, blood type, country affiliation, rating, etc.

Let us see two examples:

  • Create Categorical Series in Pandas
  • Create Categorical DataFrame in Pandas

Create Categorical Series

Use the dtype=”category” while creating a series to create a Categorical Series. Let us see an example:

Output

Create Categorical DataFrame

Use the dtype=”category” while creating a DataFrame to create a Categorical DataFrame. Let us see an example. We have created 3 categories here:

Output

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

Pandas - Statistical Functions
Working with Categories in Pandas
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading