What is the first tool that comes to mind when you have data related to the region? Echarts, Basemap (late update), Pyecharts, Matplotlib, Seaborn, etc? But today we’ll start with Pyecharts.

1. Pyecharts is introduced

Pyecharts class library for generating Echarts ICONS, Pyecharts is a data visualization JS library for Pyecharts

2. Download the base map

Since V0.3.2, In order to reduce the size of the project itself and keep pyecharts projects lightweight, Pyecharts will no longer ship with map JS files. If users need to use map and chart, they can install the corresponding map file package by themselves. Here is how to install it.

pip install echarts-countries-pypkg pip install echarts-china-provinces-pypkg pip install echarts-china-cities-pypkg pip  install echarts-china-counties-pypkg pip install echarts-china-misc-pypkgCopy the code
    1. Echarts – Countries – PYPkg (1.9MB): Map of the World and 213 countries, including China –
    1. Provincial map of China: Echarts-China-Provinces-Pypkg (730KB) : 23 provinces and 5 autonomous regions
    1. Echarts-china-cities-pypkg (3.8MB) : 370 Cities in China
    1. Counties map of China: Echarts-China-Counties pYPkg (4.1MB) : 2882 counties in China
    1. Echarts-china-misc-pypkg (148KB) : Maps of 11 Regions in China, such as North and South China.

3. I like pandas

  • Merge By default, merge by the same field, and take both.
    import pandas as pd
    df1=pd.DataFrame({'name': ['kate'.'herz'.'catherine'.'sally'].'age',28,39,35: [25]}) df2 = pd. The DataFrame ({'name': ['kate'.'herz'.'sally'].'score',60,90: [70]})# 1. Merge Defaults to merge by the same field and takes both.
    pd.merge(df1,df2)
    # 2. Use left_ON, right_ON when left and right join fields are different
    pd.merge(df1,df2,left_on="name",right_on='call_name')
    # 3. After the merge, delete the duplicate columns
    pd.merge(df1,df2,left_on='name',right_on='call_name').drop('name',axis=1)
    1). Default: inner join, set intersection 2). Outer join, set union, fill with nan"
    pd.merge(df1,df2,on='name',how='inner')
    df3=pd.DataFrame({'name': ['kate'.'herz'.'sally'.'cristin'].'score',60,90,30: [70]}) pd. The merge (df1, df3, on ='name',how='outer')    
    Copy the code
  • Set_index can set a single index or a composite index.
    DataFrame.set_index(keys, drop=True, append=False, inplace=False, verify_integrity=False) 
    If drop is False and inplace is True, the index will be restored to a column
    Copy the code
  • Reset_index restores the index to the default integer index
    Datafame. Reset_index (level=None, drop=False, inplace=False, col_level=0, col_fill= ")# level controls the index of the level to be restored
    If # drop is False, the index column will be restored to normal, otherwise it will be lost
    Copy the code
  • Loc, ILOC, IX differences
    If you know column names and index, and both are easy to type, select.loc
     df.loc[0, 'a']  
     df.loc[0:3, ['a'.'b']]  
     df.loc[[1, 5], ['b'.'c']]
    # ilOC allows us to slice the data for column.Df. Iloc [1, 1] df. Iloc [3-0, [0, 1]] df. Iloc [[0, 3, 5], 2-0]# ix is even more powerful, allowing us to mix subscripts and names for selection
    Copy the code

4. Data processing

  • Anjuekefangjia.csv collates the average housing price data of some cities in China from 2009 to 2018

5. Examples

Data file reading

Df = pd.read_csv(CSV file)local = df.set_value(index) 
Copy the code
  • 1. Polar coordinates of average housing prices in some Chinese cities from 2009 to 2018
    from pyecharts import Polar
    radius = [u"2009", u"2010", u"2011", u"2012",
    u"2013",u"2014",u"2015",u"2016",u"2017",u"2018"]
    # polar = polar (u"2009 -- 2018 大 量 选 项 选 项 选 项 ", width=1200, height=1100) # polar = polar (u"2009 -- 2018 大 量 选 项 选 项 选 项 ", width=1200, height=1100)
    polar = Polar( width=1200, height=1100)
    for name in df.city_name:
       if len(local.ix[name][2:])<5:
           continue
       polar.add(name, local.ix[name][2:], radius_data=radius,
               type='barRadius', is_stack=True)
    polar.render()
    Copy the code
  • Results show
    1. Average housing price heat map of some cities in China in 2018
    from pyecharts import Map
    map = Map("", width=1200, height=600)
    map.add(Average Housing prices in Major Cities in China in 2018, df.province, df.price,       maptype='china',visual_text_color='# 000',is_visualmap=True, is_label_show=True)
    map.render()
    
    Copy the code
  • Results show
  • 3. 2009-2018 Average housing price trend line chart of some Cities in China
    from pyecharts import Line
    attr = [u"2009", u"2010", u"2011", u"2012",u"2013",
           u"2014",u"2015",u"2016",u"2017",u"2018"]
    line = Line(u"Trends in Housing prices in some Cities across China",height=1000,width = 1200)
    for name in df.city_name:
        if len(local.ix[name][2:]) < 10:
            continue
        line.add(name, attr,local.ix[name][2:],
             mark_point=["max"."min"],  mark_line=["average"],
             yaxis_formatter="Yuan/m squared")
    line.render()
    Copy the code
  • Results show

Detailed code and sample HTML file post-collation timely update, can also be private message oh