Код: Выделить всё
dates = pd.date_range(start ='1-1-2018', end ='1-10-2018', freq ='1D')
np.random.seed(42)
temp = np.random.randint(60, 80, size=10)
df = pd.DataFrame({'dates': dates, 'temp':temp})
df["is_hot"] = np.where(df["temp"] > 70, 1, 0)
даты
temp
is_hot
0
2018-01-01 00:00:00
66
0
1
2018-01-02 00:00:00
79
1
2
03.01.2018 00:00 :00
74
1
3
2018-01-04 00:00:00
70
0
42018-01-05 00:00:00
67
0
5
2018-01-06 00:00:00
66
0
6
2018-01-07 00:00:00
78
1
7
2018-01-08 00:00:00
70
0
8
2018-01-09 00:00:00
70
0
9
2018-01-10 00:00:00
63
0
Я могу находить полосы, но хочу, чтобы они разрывались, когда мы получаем значение is_hot, равное 0 между ними.
Я использую это
Код: Выделить всё
df['streak'] = df.loc[df['is_hot'].eq(1)].groupby(df['is_hot'])['is_hot'].cumsum()
даты
temp
is_hot
полоса< /th>
0
2018-01-01 00:00:00
Подробнее здесь: https://stackoverflow.com/questions/785 ... her-column