簡體   English   中英

獲取行索引,該列與另一個整數列表中的任何整數匹配

[英]Get index of rows which column matches any integer in another list of integers

所以我有一個數據集是從另一個更大的數據集中得出的。 它是一個基因表達數據集,因此它們中的一些樣本值得關注,因為它們取自大腦區域,該區域是特定目標網絡的一部分。 唯一標識符稱為好

d = {'network_name': [dDMN, Salience, Salience, Visual, dDNM], 'well_id': [11, 52, 37, 14, 89]}
small_df = pd.DataFrame(data=d)

bigd = {'Brain_region': [Hp, PFC, dlPFC, V2, Striatum, PFC, V1, Cerebellum], 'well_id': [54, 45, 89, 14, 11, 52, 23, 37]}
big_df = pd.DataFrame(data=bigd)

所以說我對Salience網絡感興趣。 我想要well_id的索引與在network_name中標記為Salience的Well_id列表匹配。 我找到了拉well_id並創建well_id列表的方法。

def pull_well_id (network):
    #takes in the sample annotation datasets as a list of dataframes and the network of interest
    #returns the well ids of all the samples in the list
    well_ids=list(small_df[small_df['network_name']==network]['well_id'])

    return well_ids

IDs=pull_well_id('Salience')


現在,我想獲取與big_df中的此列表匹配的well_ids的索引。 我努力了...

ID_index=list(big_df[big_df['well_id']==IDs.index.values)

但這根本不起作用。 有什么建議么

isin核對

big_df.index[big_df.well_id.isin(IDs)]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM