Search code examples
pythondbscan

amp keyword in python showing syntax error


I am following a tutorial and I am confused what this line is doing because it's not running and syntax error:

rs = rep_points.apply(lambda row: df[(df['lat']==row['lat']) && (df['lon']==row['lon'])].iloc[0], axis=1)

Syntax Error: Invalid Syntax at &amp

Tutorial Link: https://geoffboeing.com/2014/08/clustering-to-reduce-spatial-data-set-size/

Can someone help me what can I do instead of this or how to correct this?


Solution

  • The answer is probably to replace && with a single &.

    There are two mistakes that happened here:

    1. The blog software replaced && with &&. Because in HTML, & is special, you need to write it as & in your HTML source to get a literal & in the browser. It looks like the blog software made that translation once too many.
    2. The author wrote && (the operator for logical and in languages like C) while they meant either and or &. Given that we're using dataframes, my initial guess would be that the right answer is &.