Raster iteration in pygmt.grdtrack

Hello, I am a newbie to PyGMT.

I am trying to iterate through multiple rasters and extract data from them using coordinates. Then, I would like to create df_unified_raster_data dataframe.

The code is as follows:

for name, raster in rasters.items():
#creates a dataframe of the random coordinates and the values of the raster at those coordinates
      df_track = pygmt.grdtrack(
#reads a dataframe of only longitudes and latitudes to get coordinates
       points = df_coordinates,
#reads the raster
            grid = raster,
#uses bilinear because raster values are not catagorical
            interpolation = ‘l’,
#name of the column in the new “df_track” dataframe that will hold the extracted raster values
            newcolname = name

#adds the extracted raster values to the unified dataframe
      df_unified_raster_data[name] = df_track[name]

When running the first part, I am getting a message GMTInvalidInput: Unrecognized data type for grid: <class ‘pandas.core.frame.DataFrame’>

Could you please advise how to do this properly?

the code is reused from https://hackernoon.com/sampling-raster-values-at-specific-coordinates-with-python

It looks like your raster is not a grid (e.g. NetCDF/GeoTiff/xarray.DataArray), but a pandas.DataFrame table?