# Possible workarounds for pygmt bug/missing feature?

**URL:** https://forum.generic-mapping-tools.org/t/possible-workarounds-for-pygmt-bug-missing-feature/5336
**Category:** PyGMT Q&A
**Created:** [September 13, 2024, 3:44pm UTC](https://forum.generic-mapping-tools.org/t/possible-workarounds-for-pygmt-bug-missing-feature/5336 "2024-09-13T15:44:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Feva67](https://avatars.discourse-cdn.com/v4/letter/f/51bf81/32.png) [@Feva67](https://forum.generic-mapping-tools.org/u/Feva67)
#### Post date: [September 13, 2024, 3:44pm UTC](https://forum.generic-mapping-tools.org/t/possible-workarounds-for-pygmt-bug-missing-feature/5336/1 "2024-09-13T15:44:06Z")

</div>

This might be more of a pandas-based question rather than pygmt, but I feel it’s better to ask here first. I have a geolocated dataframe where I wanna take subsets of data and run pygmt.grdtrack, with a different grid for each subset. That shouldn’t be much of a problem if grdtrack handled dataframe indexes correctly, as I could make a copy of said dataframe slice, and guarantee the output would match the input indexes and I could assign those values to the original df. However, as stated in this report: [https://github.com/GenericMappingTools/pygmt/issues/2763](https://github.com/GenericMappingTools/pygmt/issues/2763)  
grdtrack doesn’t allow for non default index. My first idea was to run a merge\_asof between the output of grdtrack and the original dataframe, but that can’t be done for multiple subsets. I also thought about assuming the order of the points wouldn’t be changed after the grdtrack, so I could assign the output to the same original slice without checking for index, but the order does change when a point falls outside the grid. With all that in mind, is there any way to implement grdtrack to my problem? Thank you very much!

---

<div class="post-metadata">

### Author: ![Feva67](https://avatars.discourse-cdn.com/v4/letter/f/51bf81/32.png) [@Feva67](https://forum.generic-mapping-tools.org/u/Feva67)
#### Post date: [September 16, 2024, 3:08pm UTC](https://forum.generic-mapping-tools.org/t/possible-workarounds-for-pygmt-bug-missing-feature/5336/2 "2024-09-16T15:08:35Z")

</div>

Replying to it as I figured a pretty convenient way:

```auto
df['index'] = df.index
df['new']=np.nan
for condition in conditions:
  slice=df[df[condition]][['lon','lat','index']].copy()
  slice.reset_index(drop=True, inplace=True)
  slice=pygmt.grdtrack(grid=grid, points=slice,newcolname='new')
  slice.set_index('index', inplace=True)
  df.update(slice['new'])

```

It still seems a bit roundabout and will be hoping for a future pygmt update that includes dealing with custom dataframe indexes correctly
