Код: Выделить всё
# Steps:
# pick common substring
# add actions that the substring covers to list
# query the shots for the actions until empty
commonSubstrings = ['Jump','Layup','Dunk','Fadeaway','Hook','Bank','Tip']
actions = shots[shots.action_type.str.contains('|'.join(commonSubstrings))].action_type.to_list()
shots.query('action_type not in @actions').action_type
# replace each shot type with the new label
def get_label(row):
for s in commonSubstrings:
if s in row.action_type:
return s
shots['shot_type'] = shots.apply(lambda x: get_label(x), axis=1)
Код: Выделить всё
actions = shots[shots.action_type.str.contains('|'.join(commonSubstrings))].action_type.to_list()
Подробнее здесь: https://stackoverflow.com/questions/789 ... ta-science