I would like to get a CSV file with x,y coordinates and the correspondent single raster band value: (x, y, value)

This is my code:

from osgeo import gdal

import pandas as pd

import numpy as np

import os

import matplotlib.pyplot as plt

evapotr = gdal.Open('example.tif')

evapotr_trans = gdal.Translate('example.xyz', evapotr)

evapotr_trans_csv = pd.read_csv('example.xyz', sep= " ", header = None)

evapotr_trans_csv.columns = ["x", "y", "ET0"]

evapotr_trans_csv.to_csv('example.csv', index = False)

the result is (only no-values):

enter image description here

I get also to many rows, vectorizing the raster in Qgis I have an attribute table made of: 8061 rows

While, if I check for the min and max raster value:

srcband = evapotranspiration.GetRasterBand(1)

# Get raster statistics
stats = srcband.GetStatistics(True, True)

enter image description here

I get the real min and max.

What could be the issue here?

1 Answer 1


You encounter a common issue when working on a georeferenced raster using pandas and numpy. Printing the table displays only the head and tail pixels which are usually in the nodata area shown in green rectangles.

enter image description here

You will get some pixel values if you use an index range as follows:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.