I have two different datasets. One dataset describes levels and a location (contains 4 files). The second dataset describes technologies and a location (contains 3 files).
import os
import pandas as pd
import glob
technology = glob.glob("C:\\path\\*.xlsx", recursive = True)
level = glob.glob("C:\\path\\*.xlsx", recursive = True)
d = {}
for level, technology in zip (level, technology):
d[level technology] = pd.merge(technology, level, how= "inner",left_on=["Location"],right_on=["Location"])
d.to_excel(d[level technology]+ '.xlsx')
- With d ={} I try to create a dataframe, which I can rename.
- With the for loop I try to merge every single technology file with every single level file based on the columns Location. 3.To save the 12 files based of a merge of the technology and the level based on their orginal file names....
Am I even use right method ? At the moment I get the following error message: TypeError: Can only merge Series or DataFrame objects, a <class 'str'> was passed
The issue you're encountering stems from a misunderstanding of how pandas.merge and file handling work in this context. Your technology and level variables are lists of file paths (strings), not DataFrame objects. You need to load these files into pandas DataFrames before you can merge them.