1
這是一種獨特的連接/組合,但我不知道這稱爲什麼,所以請隨時用術語來糾正我。pandas從系列B中獲得也在系列A中的條目;但只有在系列A中唯一的條目將具有填充值0
所以,比如我有一個系列profile
如下:
In [1]: profile = pd.Series(data=[0.8,0.64,0.51,0.5,0.5], index=['google.com','facebook.com','twitter.com', 'instagram.com', 'github.com'])
In [2]: profile
Out[2]:
google.com 0.80
facebook.com 0.64
twitter.com 0.51
instagram.com 0.50
github.com 0.50
dtype: float6
而且我有一個transaction
系列如下:
In [3]: transaction = pd.Series(data=[1,1,1,1], index=['twitter.com','facebook.com','instagram.com','9gag.com'])
In [4]: transaction
Out[4]:
twitter.com 1
facebook.com 1
instagram.com 1
9gag.com 1
dtype: int64
我想實現的是,我比較了一系列window
profile
和transaction
:如果transaction
中的索引也存在於profile
中,則我們得到該特定索引和它的相應值。其餘的指數,只有在profile
是唯一有權0
In [5]: window
Out[5]:
google.com 0
facebook.com 1
twitter.com 1
instagram.com 1
github.com 0
dtype: int64
填充值是否有任何現有的內置方法/功能可以做到這一點?
我已經嘗試:
window = transaction[transaction.keys().isin(profile.keys())]
但它只返回transaction
和profile
的交集。 我在Series
中遇到了這個combine()
函數,但我不知道在func
參數(isin()
無效)中應用了什麼。
這樣比較好。如果'transaction'中沒有'profile',它不會得到一個關鍵錯誤。 – anobilisgorse