2
votes

Hi Stack Overflow community!

I have a dataframe that includes 2 columns of UTM coordinates ('X' and 'Y') as shown on the screenshot below:

utm coordinates

I have been trying to convert and replace those 2 columns into Longitude and Latitude as shown below:


    Longitude   Latitude
    1.601554    42.546245
    53.847818   23.424076
    67.709953   33.93911

    ... and so on

Here's the code I usded:


    def rule(row):
        lat, lon = utm.to_latlon(row["X"], row["Y"])
        return pd.Series({"lat": lat, "long": long})
    df.merge(df.apply(rule, axis=1), left_index= True, right_index= True)

FYI, to import utm, I have installed the utm 0.4.2 using Terminal.

However, it keeps giving me the following Type Error when i ran the code:

type error

I am really new to data science and Python, so it is very difficult for me to figure out what I have done wrong.. :'(

Any helps or advice would be greatly appreciated!

1

1 Answers

2
votes

If you look at the documentation for utm, you'll note that to_latlon takes four required arguments. You've only given it two (latitude and longitude), so you're missing Zone Number (as seen in the error) plus Zone Letter.