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 ...
Answers:
I think need compare by first value with all
for check all True
s:
out = df['date'].eq(df['date'].iat[0]).all()
Numpy solution:
arr = df['date']
out = np.all(arr == arr[0])
You can count unique values and check if it is more than one or not
df.agg({'date': pd.Series.nunique}) == 1
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 ...
I think need compare by first value with all
for check all True
s:
out = df['date'].eq(df['date'].iat[0]).all()
Numpy solution:
arr = df['date']
out = np.all(arr == arr[0])
You can count unique values and check if it is more than one or not
df.agg({'date': pd.Series.nunique}) == 1