Python folium problem with removing NAN from the popup

33 views Asked by At

I have the excel list with some blanks columns. I would like to remove NAN, but I don't know how.

I used the dropna() function, but didn't work in my case.

 df = pd.read_csv("work2.csv")

 for i,row in df.iterrows():
lat = df.at[i, 'lat']
lng = df.at[i, 'lng']
sp = df.at[i, 'sp']
stat = df.at[i,'title']
skill = df.at[i,'skillset']
skill2 = df.at[i,'skillset2']
#skill3 = df.at[i(float).notna(), 'skillset3']
skill4 = df.at[i,'skillset4']

but I get the TypeError

Is there any way of removing the NaN from the Python folium popup which uses data manipulated by pandas?

The solution proposed here:

'str' object has no attribute 'dropna'

leads to the situation where I have only one input visible.

enter image description here

1

There are 1 answers

0
Timeless On

Assuming the skills are on the rightmost side of your df, you could use pd.notna this way :

for lat, lng, sp, stat, *skillsets in df.to_numpy():
    html = "<ul>"
    for skill in skillsets:
        if pd.notna(skill):
            html += f"<li>{skill}</li>"
    html += "</ul>"

    iframe = folium.IFrame(html) # to be adjusted if needed
    popup = folium.Popup(iframe, min_width=300, max_width=300)

    _ = folium.Marker([lat, lng], popup=popup).add_to(m) # or whatever