So in order to refresh my powerBI dashboard I need to write queries to Excel. Otherwise I have to run every single query and do it myself.
I now build the following Python code:
import pandas as pd
from pathlib import Path
data_folder = Path("PATH")
file_to_open = data_folder / "excelfile.xlsx"
df = pd.read_excel(file_to_open)
query_1 = 5
query_2 = 3
query_3 = 12
df.loc[df.iloc[-1,-1]+1,['A']] = query_1
df.loc[df.iloc[-1,-1]+1,['B']] = query_2
df.loc[df.iloc[-1,-1]+1,['C']] = query_3
print(df) #for testing#
df.to_excel(file_to_open, index = False)
It somehow puts query_1 in the right spot (right after the last value in column A) But query_2 and query_3 both skip one cell. They should all fill in the next empty cell in my excelsheet. My columns are A, B and C.
Can someone help me out?