Creating a separate Counter() object and Pandas DataFrame for each list within a list of lists

后端 未结 2 1773
再見小時候
再見小時候 2021-01-28 08:24

All the other answers I could find specifically referred to aggregating across all of the nested lists within a list of lists, where as I\'m looking to aggregate separately for

2条回答
  •  广开言路
    2021-01-28 09:23

    You can create a list and append the counters to it. (Also, you are using Counter, but still doing the counts yourself, which is unnecessary.)

    master_list = [[a,a,b,b,b,c,c,c], [d,d,d,a,a,a,c,c,c], [c,c,c,a,a,f,f,f]]
    counters = []
    for list_ in master_list:
        counters.append(Counter(list_))
    

    Now you can address each separate list with counters[i].

提交回复
热议问题