Skip to content
Advertisement

Analysing height difference from columns and selecting max difference in Python

I have a .csv file containing x y data from transects (.csv file here). The file can contain a few dozen transects (example only 4).

I want to calculate the elevation change from each transect and then select the transect with the highest elevation change.

JavaScript

I’ve tried to calculate the change with pandas.dataframe.diff but I’m unable to select the highest elevation change from this.

UPDATE: I found a way to calculate the height difference for 1 transect. The goal is now to loop this script through the different other transects and let it select the transect with the highest difference. Not sure how to create a loop from this…

JavaScript

Ideally, the script would select the transect with the highest elevation change from an unknown number of transects in the .csv file, which will then be exported to a new .csv file.

Advertisement

Answer

You need to groupby by column lines.

Not sure if this is what you meant when you say elevation change but this gives difference of elevations (max(y) – min(y)) for each group, where groups are formed by all rows sharing same value of ‘line’each group representing one such value. This should help you with what you are missing in your logic, (sorry can’t put more time in).

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement