Все уведомления (даже другие уведомления о приложениях) можно удалить, прослушивая «NotificationListenerService», как указано в NotificationListenerService Implementation
. В службе вы должны вызвать cancelAllNotifications()
.
Услуга должна быть включена для вашего приложения через:
'Apps & amp; уведомления »->« Доступ к специальному приложению »->« Доступ к уведомлениям ».
import pandas as pd
df = pd.DataFrame(data={"col1": [1,1,100,1,1,100], 'col2': [1,1,100,1,1,100]})
# get list of columns (will be used later)
cols = df.columns
# create list of next division by 2 (will be used later)
original = 100
ll = []
for x in range(1, 20):
ll.append(original)
original /= 2
ll = list(zip([x for x in range(1, 20)], ll))
# create dictionary of indexes and divisions
dd = {x:y for x,y in ll}
for c in df.columns:
df[f'{c}_next'] = df[c].shift(-1)
# main function get 1&100 pairs and replacing values
def compare_vals(row, cols):
counter = 1
for c in cols:
if row[f'{c}_next'] == 100 and row[c] == 1:
counter += 1
for c in cols:
if row[f'{c}_next'] == 100 and row[c] == 1:
row[f'{c}_next'] = dd[counter]
return row
df_new = df.apply(lambda row: compare_vals(row, cols), axis=1)
df_new = df_new[[x for x in df_new.columns if x not in cols]]
cols_new = {x: x.replace('_next', '') for x in df_new.columns}
df_new = df_new.rename(columns=cols_new)
df_new = df_new.shift(1)
df_new.iloc[0, :] = df.iloc[0,:]
ВЫХОД
col1 col2
0 1.0 1.0
1 1.0 1.0
2 25.0 25.0
3 1.0 1.0
4 1.0 1.0
5 25.0 25.0
Я думаю, сделать это для каждого столбца в отдельности. Нужно формировать группы для каждого столбца каждый раз, когда вы встречаете 100.
import pandas as pd
for col in df.columns[1:]:
df[col] = (df[col].groupby(df[col].eq(100).shift(1).fillna(0).cumsum())
.apply(lambda x: x.mask(x == 100, 100/(2**x.eq(1).sum()))))
rule_id 51594 51668 51147 51182 51447
0 comparison1 1.0 1.0 NaN NaN NaN
1 last_comp 50.0 50.0 NaN NaN NaN
2 comparison1 NaN NaN 1.0 NaN 1.0
3 comparison2 100.0 NaN 1.0 NaN 1.0
4 comparison3 NaN NaN 1.0 100.0 25.0
5 comparison4 NaN NaN 12.5 NaN NaN