I'm working with this python package called UTM, which converts WGS84 coordinates to UTM and vice versa. I would like to apply this function to a pandas dataframe. The function works as follows:
utm.from_latlon(51.2, 7.5)
>>> (395201.3103811303, 5673135.241182375, 32, 'U')
where the input is a couple of coordinates, and it returns a tuple of the same coordinates in UTM system. For my purposes I'm interested only in the first two elements of the tuple.
I'm working on a Dataframe called cities
like:
City;Latitude;Longitude;minx;maxx;miny;maxy
Roma;41.892916;12.48252;11.27447419;13.69056581;40.99359439;42.79223761
Paris;48.856614;2.352222;0.985506011;3.718937989;47.95729239;49.75593561
Barcelona;41.385064;2.173403;0.974836927;3.371969073;40.48574239;42.28438561
Berlin;52.519171;13.406091;11.92835553;14.88382647;51.61984939;53.41849261
Moscow;55.755826;37.6173;36.01941671;39.21518329;54.85650439;56.65514761
and I would like to add four columns for each row called 'utmminx','utmmax','utmminy','utmmaxy' as a result of applying the utm function to the 'minx','maxx','miny','maxy' columns. So far I tried the following, assigning the first and the second value of the resulting tuple to the new columns:
cities['utmminx'],cities['utmmaxx'] = utm.from_latlon(cities['minx'],cities['maxx'])[0],utm.from_latlon(cities['minx'],cities['maxx'])[1]
but I received a ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I tried to set only the first row value to the function and it works:
utm.from_latlon(cities['minx'][0],cities['maxx'][0])[0],utm.from_latlon(cities['minx'][0],cities['maxx'][0])[1]
>>> (357074.7837193568, 1246647.7959235134)
I would like to avoid classical loops over the dataframe as I thought there is a classical pandas method to do this.