<p>您可以使用<code>cumsum</code>来检测<code>A</code>列中的更改,因为在python中<code>boolean</code>可以求和。在</p>
<pre><code># Test data
df= DataFrame([True, True, False, False, False, False, True, False, False],
index=pd.to_datetime(['2015-05-01', '2015-05-02', '2015-05-03',
'2015-05-04', '2015-05-05', '2015-05-06',
'2015-05-07', '2015-05-08', '2015-05-09']),
columns=['A'])
# We have to ensure that the index is sorted
df.sort_index(inplace=True)
# Resetting the index to create a column
df.reset_index(inplace=True)
# Grouping by the cumsum and counting the number of dates and getting their min and max
df = df.groupby(df['A'].cumsum()).agg(
{'index': ['count', 'min', 'max']})
# Removing useless column level
df.columns = df.columns.droplevel()
print(df)
# count min max
# A
# 1 1 2015-05-01 2015-05-01
# 2 5 2015-05-02 2015-05-06
# 3 3 2015-05-07 2015-05-09
# Getting the max
df[df['count']==df['count'].max()]
# count min max
# A
# 2 5 2015-05-02 2015-05-06
</code></pre>