【发布时间】:2021-01-11 18:30:34
【问题描述】:
我使用 pandas 从 txt 文件中加载了以下数据框 Positive Samples Dataframe
这个阳性样本数据框有一个名为 Gene Set 的列,它基本上是一个基因列表。当我运行postive_samples["Gene Set"] 时,我得到以下输出
['YAL004W', 'YLL024C'] ['YAL005C', 'YLL024C'] ['YAL005C', 'YMR006C'] ['YAL005C', 'YOL090W'] ['YAL009W', 'YBR074W'] ['YAL009W', 'YER162C'] ['YAL009W', 'YHL024W'] ['YAL009W', 'YJL187C'] ['YAL009W', 'YKR003W']
我还有另一个名为 new_expression_df New Expression Dataframe 的数据框,它以 positive_samples["Gene Set"] 列作为其索引。
所以我想要做的是获取存储在 postive_samples["Gene Set"] 中的值,并使用循环在 new_expression_df 索引中使用 loc 定位它们。
samples_column_list= ["GSM144760","GSM144761","GSM144762","GSM144763","GSM144764"]
for gene_class_column in postive_samples[['Gene Set']]:
#Select column contents by column name using [] operator
geneSeriesObj = postive_samples[gene_class_column]
gene_pairs = geneSeriesObj.values
#get gene pairs and locate their expression in the given samples
for gene_pair in gene_pairs:
new_expression_df.loc[gene_pair,samples_column_list]
当我尝试使用循环执行此操作时,我在迭代开始时遇到一个关键错误,理想情况下,我希望将每个基因集作为一个列表,使用其索引将其值定位在另一个数据框中。
但是,当我像下面那样插入每个集合而不使用循环时,它对于相同的值工作得很好,我得到了一个关键错误,那么我在这里做错了什么?
new_expression_df.loc[['YAL002W','YBL001C'],samples_column_list]
我想从另一个存储在列表中的数据框列值中动态放置 loc 函数的行参数。
【问题讨论】: