作者:
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