← 返回题库
初级

解析楼宇JSON注册请求

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd
    bld_csv = open_url("https://data.zuihe.com/dbd/ms-adlift/state_00/buildings.csv").read()
    buildings = pd.read_csv(StringIO(bld_csv))
    def parse_building(row):
        return {'id':row['building_id'],'name':row['name'],'region':row['region'],'type':row['building_type'],'floors':int(row['total_floors']),'elevators':int(row['elevator_count']),'traffic':int(row['daily_foot_traffic'])}
    print("Building registry (first 5):")
    for _, row in buildings.head(5).iterrows():
        b = parse_building(row)
        print("  "+b['id']+": "+b['name']+" region="+b['region']+" type="+b['type']+" floors="+str(b['floors'])+" elevators="+str(b['elevators']))
    print("Total: "+str(len(buildings)))
    print("By region: "+str(dict(buildings.groupby('region').size())))

示例

输入
solve()
期望输出
Building registry (first 5):
  BLD-001: 朝阳时代01号 region=朝阳 type=residential floors=9 elevators=6
  BLD-002: 海淀中心02号 region=海淀 type=commercial floors=16 elevators=3
  BLD-003: 浦东广场03号 region=浦东 type=hotel floors=13 elevators=11
  BLD-004: 天河大厦04号 region=天河 type=residential floors=9 elevators=3
  BLD-005: 江汉国际05号 region=江汉 type=commercial floors=40 elevators=11
Total: 50
By region: {'天河': np.int64(10), '朝阳': np.int64(10), '江汉': np.int64(10), '浦东': np.int64(10), '海淀': np.int64(10)}
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码