[英]Pandas merge or concat on list of pd.series. along columns. Series indexes may overlap
我正在生成一个熊猫系列列表,其中指数是温度,数据是在所述温度下存在的一些热力学固相体积。 每次运行模拟时,我不知道将返回多少个阶段,因此我将它们附加到要沿列连接的 pandas 系列列表中。 例如,假设我对 400 到 900 度的相位感兴趣,并且想要填充一个索引为所有温度的数据框。
# data.values() is an object whose values x's are temperature and y's are amount of some phase.
lst_phases = []
for d in data.values():
idx = pd.Index(d.temp)
idx.drop_duplicates(keep='first')
## sometimes there can be duplicate temperatures with an empty index in between each.
## ex. temp = [473, 478, 480, , 480, 483....] # so I drop the first, I am not sure what to do abut the empty index or if that is my issue.
s = pd.Series(d.phase, index=idx, name=d.name)
lst_phases.append(s)
result = pd.concat(lst_phases, axis=1)
返回:
ValueError: cannot reindex from a duplicat axis
我也试过像这样进行合并。
pd.merge(lst_phases[0], lst_phases[1], how='outer', left_index='True', right_index='True')
这将返回一个完整的外部连接,因此我的温度指数是所有温度,并且正是我想要达到的。 问题是很难对阶段列表进行合并,尤其是当我不知道每个模拟将有多少阶段/pd.Series 时
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.