<jupyter_start><jupyter_text>Import data Data structure requirement:- Has a column named "Lat" for latitude- Has a column named "Long" for longitude- Has filtered out all non-relevant rows<jupyter_code>filename ='data/airbnb.csv'
encoding = None
cols = None # Specify if need to consider a subset of columns


df = pd.read_csv(filename,encoding=encoding)

df['Weight'] = np.random.rand(len(df))<jupyter_output><empty_output><jupyter_text>Google Maps<jupyter_code>class GMAPS():
    def __init__(self, figure_layout = None):
        self.fig = gmaps.figure(layout = figure_layout, display_toolbar = False,
                                map_type = "TERRAIN") # Could be HYBRID

    def add_heatmap(self, data, latcol = 'Lat', loncol = 'Long', weightcol = None, point_radius = 20, **kwargs):
        """
        Creates a heatmap
        
        data: pandas dataframe. Has columns: Lat, Long, Weight. Must be cleaned beforehand
        latcol, loncol: name of latitude &  longitude cols
        weightcol: name of the numerical column used for weighting
        
        **kwargs: 
        max_intensity
        point_radius
        opacity
        gradient
        """
        if weightcol != None:
            heatmap = gmaps.heatmap_layer(locations = data[[latcol, loncol]], weights = data['Weight'], 
                                          point_radius = point_radius,**kwargs)
        else:
            heatmap = gmaps.heatmap_layer(locations = data[[latcol, loncol]], 
                                         point_radius = point_radius, **kwargs)
        self.fig.add_layer(heatmap)
        
    def add_symbols(self, symbols, latcol = 'Lat', loncol = 'Long', fill_color = 'red', stroke_color = 'red', **kwargs):
        """
        Add individual points
        symbols: pandas dataframe. Has columns: Lat, Long. Must be cleaned beforehand
        
        **kwargs: 
        fill_color
        fill_opacity
        stroke_color
        stroke_opacity
        scale
        """
        symbol_layer = gmaps.symbol_layer(locations = symbols[[latcol, loncol]], fill_color = fill_color,
                                          stroke_color = stroke_color, **kwargs) 
        self.fig.add_layer(symbol_layer)
    
    def add_json(self, filename, fill_opacity = 0, stroke_weight = 1, **kwargs):
        """
        Add geojson layer. Useful for districts, neighborhoods, US states etc
        
        **kwargs:
        fill_opacity
        fill_color
        stroke_color
        stroke_opacity
        stroke_weight = 3, range 0 to 20
        """
        with open(filename) as f:
            geojson_file = json.load(f)
            f.close
        geojson = gmaps.geojson_layer(geojson_file, 
                                      fill_opacity = fill_opacity, stroke_weight = stroke_weight, **kwargs)
        self.fig.add_layer(geojson)
        
    def display(self):
        display(self.fig)<jupyter_output><empty_output><jupyter_text>Exemple<jupyter_code>latcol = 'latitude'
loncol = 'longitude'
jsonpath = 'Boston_Neighborhoods.geojson'
catcol = 'room_type'


layout={
        'width': '600px',
        'height': '600px',
        'padding': '3px',
        'border': '1px solid black'
        }

df = df[df.city == 'Boston']

for category in df[catcol].unique():
    mymap = GMAPS(layout)
    mymap.add_heatmap(df[df[catcol] == category], latcol = latcol, loncol = loncol, point_radius = 5)
    #mymap.add_symbols(df[df['room_type'] == category].iloc[:5], latcol = latcol, loncol = loncol)
    mymap.add_json(filename = jsonpath)
    mymap.display()
mymap = GMAPS(layout)
mymap.add_heatmap(df, latcol = latcol, loncol = loncol, point_radius = 5)
mymap.add_symbols(df.iloc[:5], latcol = latcol, loncol = loncol)
mymap.add_json('Boston_Neighborhoods.geojson')
mymap.display()<jupyter_output><empty_output><jupyter_text>Bournemouth venues<jupyter_code>venues = pd.read_csv("Datasets/bournemouth_venues.csv")
venues.rename(columns = {'Venue Latitude':'Lat', 'Venue Longitude':'Long'}, inplace = True)

layout={
        'width': '600px',
        'height': '600px',
        'padding': '3px',
        'border': '1px solid black'
        }
mymap = GMAPS(layout)
mymap.add_heatmap(venues, point_radius = 20)
mymap.display()
mymap = GMAPS(layout)
mymap.add_symbols(venues)
mymap.display()
df = pd.read_csv("airbnb.csv")
df.rename(columns = {'latitude':'Lat', 'longitude': 'Long'}, inplace = True)
mymap = GMAPS(layout)
mymap.add_heatmap(df, point_radius = 20, weights = df['log_price'])
mymap.display()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11651982378854625, 'fraction_numerical': 0.007048458149779736, 'mean_word_length': 2.734375, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '437507', 'license': 'MIT', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1425, 'n_words': 322, 'path': 'GoogleMaps.ipynb', 'repo_name': 'raym96/personal', 'size': '4540'}