def get_all_categories(cat_series)cat_sets (set(to_cat_list( )for in cat_seriesreturn sorted(set union(*cat_sets)def get_english(cat)codenames cat split('if '|in namesnames names split(')[ return codenames strip(you can test out that the get_english function does what you expectin [ ]get_english(' urgences logistiques vital lines'out[ ](' ''vital lines'nowi make dict mapping code to name because we'll use the codes for analysis we'll use this later when adorning plots (note the use of generator expression in lieu of list comprehension)in [ ]all_cats get_all_categories(data categorygenerator expression in [ ]english_mapping dict(get_english(xfor in all_catsin [ ]english_mapping[' 'out[ ]'food shortagein [ ]english_mapping[' 'out[ ]'earthquake and aftershocksthere are many ways to go about augmenting the data set to be able to easily select records by category one way is to add indicator (or dummycolumnsone for each category to do thatfirst extract the unique category codes and construct dataframe of zeros having those as its columns and the same index as datadef get_code(seq)return [ split(')[ for in seq if xall_codes get_code(all_catscode_index pd index(np unique(all_codes)dummy_frame dataframe(np zeros((len(data)len(code_index)))index=data indexcolumns=code_indexif all goes welldummy_frame should look something like thisin [ ]dummy_frame ix[:: out[ ]int index entries to data columns non-null values non-null values non-null values non-null values plotting and visualization www it-ebooks info