[Solved] How do I loop through a single data frame column to count how many different values there are?


you have to use df.unique(). That’s why pandas is used. You are not supposed to loop through pandas.

Even for applying manipulations to the data inside dataframe you should go for df.apply().

This should get the list of unique date values as a list:

df.Date.unique()

In case, you want to use loop:

Use df.iterrows() :

def findUniqueDates(df):
    unique_dates = []

    for index, row in df.iterrows():
        if row['Date'] not in unique_dates
        unique_date.append(row['Date'])
    return unique_dates

2

solved How do I loop through a single data frame column to count how many different values there are?