Search code examples
pythonpandasgeolocationpyproj

apply function on two columns in python pandas with 2 arguments (convert GPS type to another)


so i have a database of X and Y coordinates as the ITM type and i want it as WGS-84 type. i found a function from pyproj library thats convert and it works great but now i'm having troubles to apply this function on two separate columns.

for example i want to convert this data :

Column x Column y
643234 234562
634352 434534

to something like that

Column X Column Y
33.04647 35.56525
25.34533 23.43532

so my function accepts two arguments(X from Column x and Y from column y) and needs to replace all the values to the new coordinates data any one has an idea how to use the apply function to work on both columns

i tried to use apply function on both column but it didn't worked out and i couldn't find a solution online and i also tried to change my Function to work separately on one column but its impossible because its a built in function of a certain library


Solution

  • https://github.com/geopandas/geopandas/issues/1400

    from pyproj import Transformer
    
    trans = Transformer.from_crs(
        "epsg:4326",
        "+proj=utm +zone=10 +ellps=WGS84",
        always_xy=True,
    )
    xx, yy = trans.transform(My_data["LON"].values, My_data["LAT"].values)
    My_data["X"] = xx
    My_data["Y"] = yy