Roll Class Country Rights CountryAcc
1 x IND 23 US
1 x1 IND 32 Ind
2 s US 12 US
3 q IRL 33 CA
4 a PAK 12 PAK
4 e PAK 12 IND
5 f US 21 CA
5 g US 31 PAK
6 h US 21 BAN
我想只顯示那些Rolls
其CountryAcc
不US
或CA
。例如:如果Roll
1
在US
一個CountryAcc
然後我不希望它的其他一行CountryAcc
Ind
和同去與Roll
5
,因爲它是具有一行與CountryAcc
爲CA
。所以,我最後的結果將是:
Roll Class Country Rights CountryAcc
4 a PAK 12 PAK
4 e PAK 12 IND
6 h US 21 BAN
我試圖讓下面的方式輸出:
Home_Country = ['US', 'CA']
#First I saved two countries in a variable
Account_Other_Count = df.loc[~df.CountryAcc.isin(Home_Country)]
Account_Other_Count_Var = df.loc[~df.CountryAcc.isin(Home_Country)][['Roll']].values.ravel()
# Then I made two variables one with CountryAcc in US or CA and other variable with remaining and I got their Roll
Account_Home_Count = df.loc[df.CountryAcc.isin(Home_Country)]
Account_Home_Count_Var = df.loc[df.CountryAcc.isin(Home_Country)][['Roll']].values.ravel()
#Here I got the common Rolls
Common_ROLL = list(set(Account_Home_Count_Var).intersection(list(Account_Other_Count_Var)))
Final_Output = Account_Other_Count.loc[~Account_Other_Count.Roll.isin(Common_ROLL)]
有沒有更好的,更大熊貓或Python的方式來做到這一點。
@EdChum你能在這裏如果可能的幫助。謝謝 –
請不要發送個人要求幫助我不是你的奴隸 – EdChum
嘿,對不起,但那是苛刻的。 @EdChum –