![print unique column values in Pandas dataframe](https://vitalflux.com/wp-content/uploads/2019/12/dataframe-representing-oil-prices-300x243.jpg)
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.
![](https://vitalflux.com/wp-content/uploads/2019/12/dataframe-representing-oil-prices.jpg)
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)
Latest posts by Ajitesh Kumar (see all)
- ROC Curve & AUC Explained with Python Examples - August 28, 2024
- Accuracy, Precision, Recall & F1-Score – Python Examples - August 28, 2024
- Logistic Regression in Machine Learning: Python Example - August 26, 2024
Leave a Reply