from pyecharts.charts import Map from pyecharts import options as opts import pandas as pd from getData import getData def map(): getData() data = pd.read_csv('北京市区房价.csv',encoding='utf-8') info = data[['行政区','均价(元/㎡)']].copy() # 移除千分号,转换为浮点数,然后四舍五入到最接近的整数(或者直接使用astype(int)向下取整) info['均价(元/㎡)'] = info['均价(元/㎡)'].str.replace(',', '').astype(float).round().astype(int) info_list = info.values.tolist() print(info_list) map=Map( init_opts=opts.InitOpts( page_title="地图" ) ) map.add( series_name="平均房价", data_pair=info_list, maptype="北京", zoom=1, ) map.set_global_opts( title_opts=opts.TitleOpts( title="北京市市区", pos_left='center', ), legend_opts=opts.LegendOpts( pos_left="left", # 图例在左边 orient="vertical" # 垂直排列图例 ), visualmap_opts=opts.VisualMapOpts( max_=130000, min_=19000, range_color=['#1E9600','#fff200','#ff0000'] ) ) map.render('map.html')