bw2calc 1.8.2中LCA.to_dataframe无法导出LCI数据的问题咨询
bw2calc 1.8.2 导出LCI数据的替代方法
问题背景
此前使用bw2calc旧版本时,可通过LCA.to_dataframe(matrix_label="inventory", cutoff=None)导出LCI数据,但升级到1.8.2版本后执行代码报错:
LCA.to_dataframe() got an unexpected keyword argument 'matrix_label'
原报错代码:
import bw2calc as bc import bw2data as bd print(bc.__version__) eidb = bd.Database("ecoinvent 3.5 cutoff") # 随机选取活动 random_act = eidb.random() funct_unit = {random_act:1} # 初始化LCA并计算 lca = bc.LCA(funct_unit, ('IPCC 2021', 'climate change', 'global warming potential (GWP100)')) lca.lci() lca.lcia() # 报错行 lca.to_dataframe(matrix_label = "inventory", cutoff = None)
解决方案
bw2calc 1.8.x版本对数据导出方法做了拆分,不再通过matrix_label参数指定矩阵类型,而是提供了专门的导出方法:
- 使用
lci_to_dataframe()直接导出LCI库存数据,保留cutoff参数支持 - 对应影响评价结果可使用
lcia_to_dataframe()导出
修改后的代码:
import bw2calc as bc import bw2data as bd print(bc.__version__) eidb = bd.Database("ecoinvent 3.5 cutoff") random_act = eidb.random() funct_unit = {random_act:1} lca = bc.LCA(funct_unit, ('IPCC 2021', 'climate change', 'global warming potential (GWP100)')) lca.lci() lca.lcia() # 导出LCI数据,支持cutoff过滤 lci_df = lca.lci_to_dataframe(cutoff=None)
这个方法的功能与旧版to_dataframe(matrix_label="inventory")完全一致,无需自行手动转换lca.inventory矩阵。
内容的提问来源于stack exchange,提问作者Hannah Wang
相关产品推荐
相关产品推荐

