我将一些数据作为pandas数据帧读入Python:
Unnamed: 0 Initial_guess Lower_bound Upper_bound Estimated_or_Fixed
0 Ka 5 0.000001 10000 Estimated
2 Kd 5 0.000001 10000 Estimated
3 Ki 5 0.000001 10000 Estimated
5 Kr 5 0.000001 10000 Estimated
6 R1_I 5 0.000001 10000 Estimated
7 PR1 5 0.000001 10000 Estimated
8 PR2 5 0.000001 10000 Estimated
9 alpha 5 0.000001 10000 Estimated
10 Kcd 5 0.000001 10000 Estimated
12 Klid 5 0.000001 10000 Estimated
18 LR1R2_I 5 1.000000 10000 Estimated
Variable_type
0 Kinetic parameter
2 Kinetic parameter
3 Kinetic parameter
5 Kinetic parameter
6 Kinetic parameter
7 Kinetic parameter
8 Kinetic parameter
9 Kinetic parameter
10 Kinetic parameter
12 Kinetic parameter
18 Species IC
第一列unnamed: 0
是参数。我有很多模型,每个模型都包含这些参数的不同组合。我的任务是通过删除模型中不存在参数的任何行来为每个模型筛选此表。我有每个模型的字典,它们包含参数。参数可以是两种类型,species IC
或kinetic parameter
。以下是第一种型号的字典示例:
我的代码:
def write_parameter_bounds_file(self):
model1=self.all_models_dirs[0] #get first model from a list of model. I'll do it on the first model then generalize to the rest.
species=self.get_model_species(model1+'.xml') #get the species dct from this model
parameters=self.get_model_parameters(model1+'.xml')#get parameter dct from this model
param_info=self.read_parameter_bounds_template() #get all parameters from template. This is the pandas dataframe at the top.
estimated_species=[]
estimated_params=[]
for i in species.keys():
print '\n'
for j in param_info[param_info.columns[0]]:
if i==j:
estimated_species.append(i)
for i in parameters.keys():
print '\n'
for j in param_info[param_info.columns[0]]:
if i==j:
estimated_params.append(i)
param_list=estimated_params+estimated_species #This is a list of the parameters that need to be included in the output df
有人知道我如何使用param_list
过滤原始熊猫的df吗?在
谢谢
您可以将函数isin与从字典生成的列表一起使用:
并获得dataframe
df
的子集。您可以通过函数reset_index重置索引。在类似的方法可以用于dictionary
^{pr2}$Kinetic_parameter
。在总而言之:
相关问题 更多 >
编程相关推荐