I want to read an Excel file using pandas. I want to assign specific cells to certain parameters.
So my Excel contains 4 columns. First columns contains locations "s", 2nd contains the time "t" in years and 3rd and 4th column are 2 different materials that are available at this certain location at a certain time. The first few rows look like this:
s t Biomasse KWS
AT1 2025 234234 2323
AT1 2025.25 238208 0990
AT1 2025.5 20323 2939
AT2 2025 8888 2323
df = pd.read_excel("Inputdaten_Strom.xlsx", sheetname="Angebot_Nachfrage")
for m in M:
if m == "Biomasse":
i = 0
for s in S:
for t in T:
Ang[m,s,t] = df["Biomasse"][i]
i = i + 1
if m == "KWS":
i = 0
for s in S:
for t in T:
Ang[m,s,t] = df["KWS"][i]
i = i + 1
print Ang["Biomasse","AT1",2025.25]
This works but is very static, since if the set S does not match the s column in the sheet, it won't work correctly. I tried something like:
Ang = {}
df = pd.read_excel("Inputdaten_Strom.xlsx", sheetname="Angebot_Nachfrage")
i = 0
for m in M:
if m == "Biomasse":
for s in df["s"]:
for t in T:
Ang[m,s,t] = df["Biomasse"][i]
i = i + 1
But it gives me a key error. Can anyone help me on how to read in values correctly and efficiently?
MandSandT?