You need to enable JavaScript to run this app. 如何将Foursquare的headerFullLocation关联到对应场所并加入Pandas表
优惠活动
大模型
产品
解决方案
定价
更多

如何将Foursquare的headerFullLocation关联到对应场所并加入Pandas表

实现方案

你每次针对单个社区发起Foursquare API请求时,返回结果里的headerFullLocation和本次返回的所有周边venues是一一对应关系,直接按以下逻辑绑定即可:

  • 第一步:每次拿到单个社区的API返回结果后,先提取当前社区信息
    current_neighborhood = results['response']['headerFullLocation']
    
  • 第二步:提取当前请求返回的所有venues列表
    venue_list = results['response']['groups'][0]['items']
    
  • 第三步:给每条venue记录新增社区字段,再汇总生成表格即可,以下是Python + Pandas的示例代码:
    import pandas as pd
    
    # 初始化存储所有venue的总表
    total_venue_df = pd.DataFrame()
    
    # 遍历你的150个社区列表发起请求
    for community in your_community_list:
        # 此处省略发起API请求的代码,得到返回结果results
        current_neighborhood = results['response']['headerFullLocation']
        venue_items = results['response']['groups'][0]['items']
        
        # 处理当前批次的venues,新增社区列
        processed = []
        for item in venue_items:
            venue_info = item['venue']
            # 新增社区字段
            venue_info['neighborhood'] = current_neighborhood
            processed.append(venue_info)
        
        # 转成DataFrame追加到总表
        batch_df = pd.DataFrame(processed)
        total_venue_df = pd.concat([total_venue_df, batch_df], ignore_index=True)
    

如果不需要保留venue的全部字段,你可以在处理时只提取需要的字段(比如名称、地址、分类、坐标等)再追加到总表中即可。

内容的提问来源于stack exchange,提问作者SoraHeart

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.20 14:36:08