I have a 37 band image that I hoping to transform so that each row is a pixel and each column a band. I am following what was suggested in this post: Create pandas DataFrame from raster image - one row per pixel with bands as columns
which works perfectly except that it does not preserve the x, y coordinates which I need to merge with a different dataset. I'm wondering if there is a way to store the coordinates in a column when using transpose.
Below is the code provided to get df with rows as pixels/columns as bands:
img=rasterio.open("img.tif")
show(img,0)
#read image
array=img.read()
#create np array
array=np.array(array)
#flatten and transpose array
pd.DataFrame(array.reshape([37,-1]).T)