In this codes where latitude is greater than 40 is replaced by nan? since restaurants['latitude']>40 implies that but according to explanation It replaces the values 0.0 in latitude is this code is incorrect or i confuse somewhere

# here our .where() function replaces latitude values greater than 40 with NaN values
restaurants['latitude'] = restaurants['latitude'].where(restaurants['latitude'] > 40, np.nan) 

# here our .where() function replaces longitude values less than -70 with NaN values
restaurants['longitude'] = restaurants['longitude'].where(restaurants['longitude'] < -70, np.nan) 

# .sum() counts the number of missing values in each column

It’s always a good idea to double check the documentation of the function or method you’re making use of if you’re unsure about the output-

The important information in this case is the line from this page: “Replace values where the condition is False.”
1 Like

It helps much One more question is the pandas in python used with the API called means It is not the module created in python

Sorry I’m not quite sure what you mean. It’s definitely not a pure Python module if that’s what you’re getting at. A lot of the functionality in based on numpy which I believe is C and Python (I think there’s even some Fortran snuck in there) and I’d assume parts of pandas itself would be the same. You’d have to look into it if you’re curious.