Pandas Check if all Dates are Equal

Question:

I am looking at the df.eq() function to check if all my dates are equal.

How would it be applied here?

I need to check that all the df.date values are equal.

       id        date   value   ...      
0       1  2016-04-30  244793   ...        
1       2  2016-04-29  244685   ...   
2       4  2016-04-30  453193   ...   
Asked By: diogenes

||

Answers:

I think need compare by first value with all for check all Trues:

out = df['date'].eq(df['date'].iat[0]).all()

Numpy solution:

arr = df['date']
out = np.all(arr == arr[0])
Answered By: jezrael

You can count unique values and check if it is more than one or not

df.agg({'date': pd.Series.nunique}) == 1
Answered By: Ali Yesilli
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.