我们如何将两个数据框列加载到 folium 的弹出窗口中?

Posted

技术标签:

【中文标题】我们如何将两个数据框列加载到 folium 的弹出窗口中?【英文标题】:How can we load two dataframe columns into a popup in folium? 【发布时间】:2022-01-21 17:56:18 【问题描述】:

我有一个看起来像这样的数据集。

Procedure   Code_Type   Code    NDC Rev_Code    Procedure_Description   Payer   Plan(s) IP_Price    OP_Price    Discounted_Cash_Price   IP_Negotiated_Charge    OP_Negotiated_Charge    PB_Negotiated_Charge    De-Identified_Minimum_Negotiated_Charge_(IP)    De-Identified_Maximum_Negotiated_Charge_(IP)    De-Identified_Minimum_Negotiated_Charge_(OP)    De-Identified_Maximum_Negotiated_Charge_(OP)    ID  hospital_name   lat lon
7509657101  EAP 96571           BRONCHOSCOPY WITH PHOTODYNAMIC THERAPY EACH ADDITIONAL 15 MINUTES   1199 NATIONAL BENEFIT FUND [5140]   1199SEIU BENEFIT FUND [514001]  1,073.73    1,073.73    429.49      32              29.82   697.92  36  Atlanta Center for Medical Research, Atlanta, GA, USA   33.739876   -84.512581
7710001A01  EAP CPT® 0001A     0771 - PREVENTIVE CARE SERVICES - VACCINE ADMINISTRATION    IMM ADMN SARSCOV2 30MCG/0.3ML DIL RECON 1ST DOSE    1199 NATIONAL BENEFIT FUND [5140]   1199SEIU BENEFIT FUND [514001]  100 100 0       40              16.94   80  41  Synergy Spinecare & Rehabilitation Medicine, Teaneck, NJ, USA   40.873272   -74.012093
7710001A01  EAP CPT® 0001A     0771 - PREVENTIVE CARE SERVICES - VACCINE ADMINISTRATION    IMM ADMN SARSCOV2 30MCG/0.3ML DIL RECON 1ST DOSE    AETNA COMM [5020]   MERITAIN HEALTH [502006]    42.35   42.35   0       29.65               16.94   80  9   Massachusetts General Hospital, Boston, MS, USA 42.3624 -71.069206
7710002A01  EAP CPT® 0002A     0771 - PREVENTIVE CARE SERVICES - VACCINE ADMINISTRATION    IMM ADMN SARSCOV2 30MCG/0.3ML DIL RECON 2ND DOSE    1199 NATIONAL BENEFIT FUND [5140]   1199SEIU BENEFIT FUND [514001]  100 100 0       40              20  80  26  Forest Hills Medical Services, Queens, NYC, NY, USA 40.73431    -73.84951
7710002A01  EAP CPT® 0002A     0771 - PREVENTIVE CARE SERVICES - VACCINE ADMINISTRATION    IMM ADMN SARSCOV2 30MCG/0.3ML DIL RECON 2ND DOSE    AETNA COMM [5020]   MERITAIN HEALTH [502006]    70.73   70.73   0       49.51               20  80  21  Park Avenue Smiles, Yonkers, NYC, NY, USA   40.945873   -73.890671
7710011A01  EAP CPT® 0011A     0771 - PREVENTIVE CARE SERVICES - VACCINE ADMINISTRATION    IMM ADMN SARSCOV2 100 MCG/0.5 ML 1ST DOSE   1199 NATIONAL BENEFIT FUND [5140]   1199SEIU BENEFIT FUND [514001]  100 100 0       40              16.94   80  17  New York’s Presbyterian Lower Manhattan Hospital, NYC, NY, USA  40.710255   -74.005058
7710011A01  EAP CPT® 0011A     0771 - PREVENTIVE CARE SERVICES - VACCINE ADMINISTRATION    IMM ADMN SARSCOV2 100 MCG/0.5 ML 1ST DOSE   AETNA COMM [5020]   MERITAIN HEALTH [502006]    42.35   42.35   0       29.65               16.94   80  50  Baptist East Hospital, Memphis, TN, USA 35.2005 -89.788216
7710012A01  EAP CPT® 0012A     0771 - PREVENTIVE CARE SERVICES - VACCINE ADMINISTRATION    IMM ADMN SARSCOV2 100 MCG/0.5 ML 2ND DOSE   1199 NATIONAL BENEFIT FUND [5140]   1199SEIU BENEFIT FUND [514001]  100 100 0       40              20  80  29  ***lyn Abortion Clinic, ***lyn, NY, New York, USA   40.689743   -73.982368
7710012A01  EAP CPT® 0012A     0771 - PREVENTIVE CARE SERVICES - VACCINE ADMINISTRATION    IMM ADMN SARSCOV2 100 MCG/0.5 ML 2ND DOSE   AETNA COMM [5020]   MERITAIN HEALTH [502006]    70.73   70.73   0       49.51               20  80  50  Baptist East Hospital, Memphis, TN, USA 35.2005 -89.788216
3100015M01  EAP CPT® 0015M     0310 - LABORATORY PATHOLOGICAL - GENERAL CLASSIFICATION ADRENAL CORTICAL TUMOR, BIOCHEMICAL ASSAY OF 25 STEROID MARKERS, UTILIZING  1199 NATIONAL BENEFIT FUND [5140]   1199SEIU BENEFIT FUND [514001]  1   1   0       0.85                0.01    0.85    34  UC Physicians Medical Arts Building, Cincinnati, Ohio, USA  39.136597   -84.505058

现在,我正在尝试创建一个显示纬度和经度的箔图,以及我的数据框中的两列。

这是我的代码。

from folium.plugins import MarkerCluster

m = folium.Map(location=[40.74, -73.98], zoom_start=10)


for i in range(0,len(df_final)):
    folium.Marker([df_final['lat'].iloc[i],df_final['lon'].iloc[i]],
            popup=df_final[['hospital_name','Discounted_Cash_Price']]).add_to(m)
        
m

当我运行它时,我得到了这个。

这里似乎包含了很多很多多余的信息。我期待一个医院名称和一个浮动的 Discounted_Cash_Price,但我得到了很多额外的东西。也许数据集没有被正确解析。知道这里可能有什么问题吗?谢谢。

【问题讨论】:

您的坐标已编入索引(即 iloc),但您的弹出窗口没有 【参考方案1】:

我得到了这个工作。

m = folium.Map(location=[40.74, -73.98], zoom_start=10)


for i in range(0,len(df_final)):
    folium.Marker([df_final['lat'].iloc[i],df_final['lon'].iloc[i]],
            popup = "Hospital: " + str(df_final.hospital_name[i]) + '<br>' +
                    "Price: " + str(df_final.Discounted_Cash_Price[i])).add_to(m)
       
m

【讨论】:

以上是关于我们如何将两个数据框列加载到 folium 的弹出窗口中?的主要内容,如果未能解决你的问题,请参考以下文章

将数据从数据库加载到 jQuery 弹出窗口

jquery easyUI 第一次点击按钮加载两个tab的datagrid 脚本报undefined的弹出框, 第二次就正常不报错了呢

如何让 Richfaces 组件在按需加载的弹出窗口中工作?

无法将 altair 可视化作为弹出窗口插入到叶地图中

将地图的一部分从openstreet加载到folium/leaflet

iframe中的弹出窗口如何显示在最外层?