I am extracting raster data using GDAL from a map that has different shades of red depending on the temperature. When I run the code within QGIS only the beginning and end of the code shows up. This is why I want to export the data into Excel, but QGIS keeps crashing when I run that part of the code. I have tried exporting the data into .csv and .txt formats but I get a Permission Denied error.
from osgeo import gdal
import pandas as pd
import openpyxl
layers=QgsProject.instance ().mapLayersByName ('1970-2000, 2.5, feb')
layer=layers [0]
ds=gdal.Open (layer.dataProvider().dataSourceUri ())
dem_arr=ds.GetRasterBand (1).ReadAsArray ()
print (dem_arr)
df=pd.DataFrame (dem_arr)
df.to_excel ("colorfirst.xlsx")