楼主:
drjoey (YES, WE SWIM)
2016-02-01 03:04:48※ 引述《busystudent (busystudent)》之铭言:
: hi 我想询问list若有重复的标签该如何相加
: 我有三组list,内容为个人所收藏的标签与其收藏次数,如下所示:
: link_a = ['a','b','c']
: bookmark_a = ['1','2','3']
: link_b = ['b','c']
: bookmark_c = ['4','5']
: link_c = ['a']
: bookmark_c = ['6']
: 我想做些计算,得到如下面的结果
: answer_link_all = ['a','b','c']
: answer_bookmark_all = ['7','6','8']
假设你的收藏次数是数字:
>>> import pandas as pd
>>> a = pd.Series(bookmark_a, link_a)
>>> b = pd.Series(bookmark_b, link_b)
>>> c = pd.Series(bookmark_c, link_c)
>>> a.add(b, fill_value=0).add(c, fill_value=0)
a 7
b 6
c 8