Predictive Hacks

Get the unique values and the type of every column of your data in one line of code

With this hack, you can get the unique values and the type of every column so you can have a better understanding of your data.

For this example, we will use the Titanic dataset from Kaggle.

import pandas as pd
import numpy as np

df=pd.read_csv('train.csv')

df.head()

The Code

pd.DataFrame({"values":{col:df[col].unique() for col in df},'type':{col:df[col].dtype for col in df}})

As you can see, the output is a data-frame that has as index the columns of our original data along with a column that contains their unique values and a column that contains their data type.

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Python

Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.

Python

Intro to Chatbots with HuggingFace

In this tutorial, we will show you how to use the Transformers library from HuggingFace to build chatbot pipelines. Let’s