【发布时间】:2015-11-09 12:04:22
【问题描述】:
我正在尝试使用 python 的 pandas 模块从 csv 文件中提取数据。实验数据有 6 列(比如说 a、b、c、d、e、f),我有一个模型目录列表。并非每个模型都有所有 6 个“物种”(列),所以我需要专门为每个模型拆分数据。这是我的代码:
def read_experimental_data(self,experiment_path):
[path,fle]=os.path.split(experiment_path)
os.chdir(path)
data_df=pandas.read_csv(experiment_path)
# print data_df
experiment_species=data_df.keys() #(a,b,c,d,e,f)
# print experiment_species
for i in self.all_models_dirs: #iterate through a list of model directories.
[path,fle]=os.path.split(i)
model_specific_data=pandas.DataFrame()
species_dct=self.get_model_species(i+'.xml') #gives all the species (culuns) in this particular model
# print species_dct
#gives me only species that are included in model dir i
for l in species_dct.keys():
for m in experiment_species:
if l == m:
#how do i collate these pandas series into a single dataframe?
print data_df[m]
上面的代码为我提供了正确的数据,但我无法以可用的格式收集它。我试图合并和连接它们,但没有快乐。有没有人知道如何做到这一点?
谢谢
【问题讨论】: