我具有以下熊猫数据框,如何检查时间列中所有行的日期是否相同?
index time bid_size bid ask ask_size
6 2019-01-07 07:45:03.000117 31 152.54 152.55 105
7 2019-01-07 07:45:03.174649 30 152.54 152.55 107
8 2019-01-07 07:45:03.217824 29 152.54 152.55 107
9 2019-01-07 07:45:03.315518 28 152.54 152.55 107
10 2019-01-07 07:45:06.234752 32 152.54 152.55 98
11 2019-01-07 07:45:10.110597 42 152.54 152.55 112
12 2019-01-07 07:45:10.126952 51 152.53 152.54 6
13 2019-01-07 07:45:10.127742 38 152.53 152.54 6
14 2019-01-07 07:45:10.173779 33 152.53 152.54 6
15 2019-01-07 07:45:10.301095 35 152.53 152.54 6
答案 0 :(得分:1)
将Series.nunique
与Series.dt.date
一起用作标量:
print (df.time.dt.date.nunique() == 1)
True
或用keep=False
和Series.duplicated
来检查是否所有值都是重复的:
print (df.time.dt.date.duplicated(keep=False))
0 True
1 True
2 True
3 True
4 True
5 True
6 True
7 True
8 True
9 True
Name: time, dtype: bool