0

I am attempting to create a new column in my dataframe that shows the distance between a set latitude and longitude against the latitude and longitude for each row in my dataframe using the line of code below:

df["dist_diff"] = geopy.distance.geodesic((place_lat, place_lon), (df_cat['lat'],df_cat['lng'])).miles

Unfortunately, the above code results in a value error as seen below:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Frustrated
  • 11
  • 1
  • I think we would need to know what value df_cat['lat'],df_cat['lng'] has. Because i cant see any obvious problems. Also does this help?: https://stackoverflow.com/questions/36921951/truth-value-of-a-series-is-ambiguous-use-a-empty-a-bool-a-item-a-any-o – xSparfuchs Apr 27 '20 at 21:08
  • df_cat['lat'] and df_cat['lng'] are numeric latitude and longitude values from my dataframe. The place_lat and place_lon are set latitude and longitude values which are defined earlier in the code. Each row in my dataframe as a latitude and longitude. – Frustrated Apr 27 '20 at 21:36
  • Are you sure that the cause of this error is in this line? – xSparfuchs Apr 27 '20 at 21:44
  • I'm afraid that link doesn't help me. It seems to explain things when you're wanting a boolean and employing a comparison. I am trying to get a column of numeric values using a calculation. Maybe the two are connected, but I am not connecting those dots. :/ – Frustrated Apr 27 '20 at 21:53
  • I am. That is the only line in that part of my little IBM notebook thingy. Everything in the cells above ran fine and appeared to look as I wanted. – Frustrated Apr 27 '20 at 21:54
  • Please provide the entire error message, as well as a [mcve]. – AMC Apr 27 '20 at 21:54
  • That is a link to the notebook. – Frustrated Apr 27 '20 at 21:56
  • looks like I needed to loop over values, though it appears that I get a warning now – Frustrated Apr 27 '20 at 22:51

0 Answers0