How to Print Unique Values in Pandas Dataframe Columns

print unique column values in Pandas dataframe

A quick post representing code sample on how to print unique values in Dataframe columns in Pandas. Here is a data frame comprising of oil prices on different dates which column such as year comprising of repeated/duplicate value of years.

Fig 1. Dataframe representing oil prices

In the above data frame, the requirement is to print the unique value of year column. Here is the code for same. Note the method unique()

for year in df['year'].unique():
  print(year)
Ajitesh Kumar

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking.
Posted in AI, Data Science, Machine Learning, News, Python. Tagged with , , .

Leave a Reply

Your email address will not be published. Required fields are marked *