Why does mapping in Folium with over 100 Circle Ma

2020-04-21 01:32发布

问题:

I'm working on producing a series of maps for an animated presentation using Folium and my code (when plotting over 100 circles) always ends in a blank map. If I decrease the number of circles to 100 or below, it works perfectly. Is this a folium limitation or something I can change on my local machine with Java or Browser settings? I'm using python in jupyter notebook in chrome on Ubuntu. merged_hourly is a pandas df with nyc foottraffic data for specific stations, lat, long, etc.

Exported Dataframe is located here as a spreadsheet: https://docs.google.com/spreadsheets/d/1XroOBPUWOqZsy-l1dwcR1iuOIn9ln69ylO16_Sqa9yc/edit?usp=sharing

# iterates columns in df
for myint in range(0,241):
    # iterates rows in df. should go to ~289, but will make a blank map
    for i in range(0,101):
        # sets some variables from the df
        R=merged_hourly[str(myint/10)][i]*.15
        lat=merged_hourly['Station_Latitude'][i]
        long=merged_hourly['Station_Longitude'][i]
        stname=merged_hourly['Station_Name'][i]
        # plots the CircleMarker
        folium.CircleMarker([lat, long], radius=R, popup=stname, color='#3186cc', 
                            fill_color='#3186cc',fill=True,
                            fill_opacity= .7).add_to(map_final)
    # saves a map with all the circle markers in a row
    map_final.save("FilePath/"+str(myint)+'.html')
    map_final=5
    map_final=folium.Map(location=[40.775036, -73.912034], zoom_start=11.25)

回答1:

The OP's dataset contains a row with an apostrophe/single quote in the Station_Name column/Series that wasn't causing an error but wasn't rendering the map either.

filter = merged_hourly['Station_Name'].str.contains("'")
print(merged_hourly.loc[filter,'Station_Name'])

101    E 143/ST MARY'S
Name: Station_Name, dtype: object

Solution was to replace the apostrophe with ' so the map renders and Station_Name correctly shows up in the popup

merged_hourly['Station_Name'] = merged_hourly['Station_Name']
                                              .str.replace("'", "'")