Brightway2导入Excel数据库报错:TypeError及未关联交换问题排查
问题:Excel导入Brightway2时触发TypeError错误
背景与操作流程
尝试将Excel表格导入Brightway2项目,最初因存在未关联交换项报错,根源是多个产品活动无法区分。为此添加了“reference product”列,用于明确需要关联ecoinvent 3.9.1 cutoff数据库的活动,并调整导入策略代码如下:
imp = bw.ExcelImporter("my_database") imp.apply_strategies() imp.match_database("ecoinvent 3.9.1 cutoff", fields=('name','unit','location', 'reference product')) #imp.match_database(fields=('name', 'unit', 'location', 'reference product')) imp.statistics()
报错详情
运行上述代码后触发TypeError,具体报错信息如下:
Cell In[193], line 5 3 imp.match_database("ecoinvent 3.9.1 cutoff", fields=('name','unit','location', 'reference product')) 4 #imp.match_database(fields=('name', 'unit', 'location', 'reference product')) ----> 5 imp.statistics() File ~/opt/.../base_lci.py:69, in LCIImporter.statistics(self, print_stats) 67 for exc in (e for e in ds.get("exchanges", []) if not e.get("input")): 68 unique_unlinked[exc.get("type")].add(activity_hash(exc)) ---> 69 unique_unlinked = sorted( 70 [(k, len(v)) for k, v in list(unique_unlinked.items())] 71 ) 73 print( 74 ( 75 u"{} datasets\n{} exchanges\n{} unlinked exchanges\n " (...) 82 ).format(num_datasets, num_exchanges, num_unlinked) 83 ) 84 return num_datasets, num_exchanges, num_unlinked TypeError: '<' not supported between instances of 'NoneType' and 'str'
疑问
- 操作过程中忽略了什么关键细节?
- 是否需要为与ecoinvent无关的活动(如生物圈、自定义活动)也指定
reference product? - 已尝试多种导入策略,但仍无法完成数据库导入,相关问题交换项存在异常。
内容的提问来源于stack exchange,提问作者user23399172
相关产品推荐
相关产品推荐

