2

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 Answers1

2

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.

Josh Friedlander
  • 10,870
  • 5
  • 35
  • 75
  • Hi @JoshFriedlander! Thank you so much for your comment! I entered the `Zone Number`, however, now it gives me the Name Error. Here's the [screenshot of the code I entered, and the error message.](https://i.imgur.com/A5pez0T.jpg) If you can offer me additional guidance, that'd be greatly appreciated! Thank you so much in advance!! – Shawn S. Choi Feb 11 '19 at 00:20
  • 1
    No problem. You have a typo here: `long` instead of `lon` – Josh Friedlander Feb 11 '19 at 04:21
  • 1
    It works! Thank you a million @JoshFriedlander! Really appreciate your help on this! – Shawn S. Choi Feb 11 '19 at 05:32