我正在尝试将多个文件导入csv
到一个文件中,DataFrame
并且在尝试添加第三个文件时出现以下错误DataFrame
。
AssertionError: cannot create BlockManager._ref_locs because block [ObjectBlock: [CompletionDate, Categories, DateEntered_x, <lots more columns here>...], dtype=object)] does not have _ref_locs set
代码是:
project = pandas.read_csv(read_csv('dbo_Project.csv')
project = pandas.read_csv(read_csv('dbo_ProjectEnergy.csv')
project = pandas.read_csv(read_csv('dbo_BuildingDescription.csv')
part_merged = pandas.merge(project, project_energy,
on='ProjectID',
how='outer')
part_merged = pandas.merge(part_merged, project_energy_data,
on='ProjectEnergyID',
how='outer')
part_merged = pandas.merge(part_merged, building_description,
on='ProjectEnergyID',
how='outer')
我应该如何加入这些DataFrames
以避免这个问题?
针对 Stefan Jansen 的回答进行了编辑:
直到发生新错误的新代码是:
project = pandas.read_csv(read_csv('dbo_Project.csv')
project = pandas.read_csv(read_csv('dbo_ProjectEnergy.csv')
part_merged = pandas.concat([project, project_energy],
axis=1,
join='outer')
part_merged.set_index(['ProjectEnergyID'])
part_merged = pandas.concat([self.part_merged,
project_energy_data],
axis=1,
join='outer')