The data information of all universities in China (including college and undergraduate, covering the whole country) is obtained from 2,769 universities in 31 provinces of China.

Pandas — Data processing — Data visualization

Install the library

pip install pyecharts

1. Import modules

Pandas Reads data

import pandas as pd
from collections import Counter
# # # drawing
from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.globals import ThemeType
from pyecharts.charts import Bar, Pie, Timeline
from pyecharts.faker import Faker

datafile = u'/home/mw/input/university_data1034/
data = pd.read_excel(datafile)
data.head()
Copy the code

2. Number of universities in different provinces

### Number of universities by province
attr = data['province'].tolist()
result = Counter(attr)
# sort
d = sorted(result.items(), key=lambda x: x[1], reverse=True)
#print(d)
#for i in d:
# print(i)
provinces = [i[0] for i in d]
value = [i[1] for i in d]

#print(provinces)
#print(value)
c = (
    Map()
        .add(""[list(z) for z in zip(provinces, value)], "china")
        .set_global_opts(
        title_opts=opts.TitleOpts(title="Segmented data"),
        visualmap_opts=opts.VisualMapOpts(max_=200, split_number=8, is_piecewise=True),
    )
)
c.render_notebook()
Copy the code

3. Count the number of universities in different cities in different provinces

## Statistics the number of universities in different cities in provinces

### all cities in Guangdong
gd_city = []
### all cities in Jilin
jl_city = []
for index, row in data.iterrows():
    if row[0] = ="Guangdong":
        gd_city.append(row[8])
    if row[0] = ="Jilin":
        jl_city.append(row[8])
print(gd_city)
print(jl_city)

gd_city_res = Counter(gd_city)
jl_city_res = Counter(jl_city)
# sort
gd_city_res1 = sorted(gd_city_res.items(), key=lambda x: x[1], reverse=True)
jl_city_res1 = sorted(jl_city_res.items(), key=lambda x: x[1], reverse=True)

guangdong_city = [i[0] for i in gd_city_res1]
guangdong_value = [i[1] for i in gd_city_res1]

jilin_city = [i[0] for i in jl_city_res1]
jilin_value = [i[1] for i in jl_city_res1]
c1 = (
    Map()
        .add("Number of Universities in Guangdong"[list(z) for z in zip(guangdong_city, guangdong_value)], "Guangdong")
        .set_global_opts(
        title_opts=opts.TitleOpts(title="Number of Universities in Guangdong"), visualmap_opts=opts.VisualMapOpts()
    )

).render(path="Number of universities in Guangdong. HTML")

c2 = (
    Map()
        .add("Number of universities by City in Jilin"[list(z) for z in zip(jilin_city,jilin_value)], "Jilin")
        .set_global_opts(
        title_opts=opts.TitleOpts(title="Number of universities by City in Jilin"), visualmap_opts=opts.VisualMapOpts()
    )

)
c.render_notebook()
Copy the code

Segmented data

4. 985, 211 and double First-class

##985, 211 and double first-class

# # # 985 schools
data_985 = []
# # # 211 schools
data_211 = []
### Double A school
data_two_one = []
for index, row in data.iterrows():
    if row[5] = =1:
        data_985.append(row[1])
    if row[6] = =1:
        data_211.append(row[1])
    if row[7] = ="Double first class":
        data_two_one.append(row[1])
print(len(data_985))
print(len(data_211))
print(len(data_two_one))
key = ['985'.'211'.'Double first-class']
value = [len(data_985),len(data_211),len(data_two_one)]
pie = (
    Pie()
        .add(
        "985, 211 and double first-class quantity"[list(z) for z in zip(key, value)],
        rosetype="radius",
        radius=["30%"."55%"],
    )
        .set_global_opts(title_opts=opts.TitleOpts("985, 211 and double first-class quantity"))
).render(path="985, 211 and double first-class number.html")
c.render_notebook()
Copy the code

5, public or private type quantity

### Number of public or private types

attr = data['Public or private'].tolist()
result = Counter(attr)
# sort
d = sorted(result.items(), key=lambda x: x[1], reverse=True)
print(d)
key = [i[0] for i in d]
value = [i[1] for i in d]
pie = (
    Pie()
        .add(
        "Quantity of Public or Private types"[list(z) for z in zip(key, value)],
        rosetype="radius",
        radius=["30%"."55%"],
    )
        .set_global_opts(title_opts=opts.TitleOpts("Quantity of Public or Private types"))
)
c.render_notebook()
[('the public'.2010), ('private'.746), (Chinese-foreign Cooperation in Running schools.13)]
Copy the code

6. Number of undergraduate or specialized courses

# Number of undergraduate or specialty

attr = data['Undergraduate or Specialist'].tolist()
result = Counter(attr)
# sort
d = sorted(result.items(), key=lambda x: x[1], reverse=True)
print(d)
key = [i[0] for i in d]
value = [i[1] for i in d]
pie = (
    Pie()
        .add(
        "Number of majors or majors"[list(z) for z in zip(key, value)],
        rosetype="radius",
        radius=["30%"."55%"],
    )
        .set_global_opts(title_opts=opts.TitleOpts("Number of majors or majors"))
)
c.render_notebook()
[('Junior College (higher vocational College)'.1461), ('General Undergraduate'.1308)]
Copy the code

7. Affiliation of different universities in China

### The affiliation of different universities in China

attr = data[Be subordinate to].tolist()
result = Counter(attr)
# sort
d = sorted(result.items(), key=lambda x: x[1], reverse=True)
print(d)
key = [i[0] for i in d]
value = [i[1] for i in d]
c = (
    Bar(init_opts=opts.InitOpts(theme=ThemeType.DARK))
        .add_xaxis(xaxis_data=key)
        .add_yaxis("The number", y_axis=value)
        .set_global_opts(
        title_opts=opts.TitleOpts(title="The affiliation of different universities in the country"),
        datazoom_opts=[opts.DataZoomOpts(), opts.DataZoomOpts(type_="inside")],
    )
        
)
c.render_notebook()
Copy the code

(‘ henan, 107), (‘ ‘in jiangsu province, 106), (” in shandong province, 106), (‘ ‘in guangdong province, 106), (‘ in hunan province, 92), (‘ anhui’, 88), (‘ the Ministry of Education, 84), (‘ ‘in hebei province, 81), (”, hubei province, 78), (‘ of liaoning province, 75), (‘ in jiangxi province, 75), (‘ sichuan ‘, 72), (‘ ‘, zhejiang province, 71), (‘ in shanxi, 67), (‘ in yunnan province, 60), (‘ in heilongjiang province, 58), (‘ in shaanxi province, 58), (‘ in guizhou province, 56), (‘ the guangxi zhuang autonomous region, 51), (‘ education department of sichuan province, 51), (‘ jiangsu province education department, 50), (‘ in fujian province, 49), (‘ jilin province ‘, 44), (‘ education department of guangdong province, 44), (43) ‘Inner Mongolia autonomous region, and (in gansu province, 43), (‘ tianjin ‘, 42), (‘ henan province education department, 42), (‘ chongqing ‘, 42), (hubei province, 40), (‘ Beijing ‘, 38), (‘ fujian province education department, 37), (” shandong province education department, 37), (‘ the xinjiang uygur autonomous region, 37), (‘ ‘in hebei province department of education, 34), (‘ zhejiang province education department, 34) and (‘ in hunan province education department, 33), (‘ Shanghai’, 31), (‘ of shaanxi province education department, 30), (‘ the anhui province education department, 29). ‘(‘ of liaoning province department of education, 28), (‘ jiangxi province education department, 28), (‘ the guangxi autonomous region education department, 24), (nan, 22), (‘ chongqing city board of education, 21), (‘ yunnan province education department, 20), (‘ heilongjiang province education department, 19), (‘ of Shanghai education commission, 18), (‘ jilin province education department, 17) (‘ Beijing municipal education commission, 15), (‘ the guizhou province education department, 15), (‘ the ningxia hui autonomous region, 14), (‘ Shanxi Province education department, 13), (‘ the Inner Mongolia autonomous region education department, 12), (‘ the tianjin education commission, 11), (‘ of hainan province, 11), (‘ in qinghai province, 11), (‘ education department of hainan province, 10), (9), ‘the Ministry of Industry and Information Technology, (‘ the Tibet autonomous region, 7), (‘ the xinjiang production and construction corps, 7), (‘ xinjiang autonomous region education department, 7), (the Ministry of Public Security, 6), (the ‘state’, 5), (‘ the Ministry of Transport, 5), (‘ gansu province education department, 5), (‘ the PLA general logistics department, 4), (‘ the people’s liberation army navy, 4), (‘ the guangxi zhuang autonomous region education department, 4), (‘ no.12, ningxia hui autonomous region, 4), (‘ the people’s liberation army general staff, 3), (‘ emergency management department, 3), (‘ the people’s liberation army air force, 3), (‘ the people’s government of shandong province, 3), (‘ of the Chinese Academy of Sciences, 2), (‘ the people’s liberation army general armaments department, 2), (‘ the united front, 2), (‘ chongqing municipal education commission, 2), (‘ armed police headquarters, 2), (‘ guizhou province people’s government, 2), (‘ the Chinese women’s federation, 1), (‘ the All-China Federation of Trade Unions’, 1), (‘ central office, 1), (‘ state general administration of sports’, 1), (‘ foreign ‘, 1), (‘ national health council ‘, 1), (Chinese Academy of Social Sciences, 1), (‘ the communist party of China central military commission, 1), (‘ the Chinese people’s armed police forces’, 1), (‘ China seismological bureau, 1), (‘ justice ‘, 1), (‘ the handan city education bureau, 1), (‘ shanxi medical university, 1), (‘ health and family planning commission of Shanxi Province ‘, 1), (‘ shanxi bureau of prisons’, 1), (‘ the people’s government of Shanxi Province, 1), (‘ the state ethnic affairs commission, 1), (‘ anshan city people’s government, 1), (‘ province education department, 1), (‘ customs’, 1), (Chinese Academy of Sciences, Shanghai, 1), (‘ zhejiang electric power company, 1), (‘ zhejiang huzhou on this education group ‘, 1), (‘ jiangxi provincial sasac, 1), (‘ the people’s liberation army nanjing military region, 1), (‘ the nanchang university, 1), (‘ jiangxi province people’s government, 1), (‘ liberation army strategic support troops’, 1), (‘ national Ministry of Water Resources and the university of hubei province people’s government to build ‘, 1), (” hubei province “, 1), (‘ of the central military commission, 1), (‘ the general armaments department, 1), (‘, ‘the people’s government of the guangxi zhuang autonomous region, 1), (‘ chongqing banan, 1), (‘ institute of chongqing released ‘, 1), (‘ southwestern university of finance and economics’, 1), (‘ dazhou, 1), (‘ the people’s government of sichuan province ‘, 1), (‘ city in sichuan province education department, 1), (‘ departments in guizhou, 1), (‘ guizhou university of finance and economics’, 1), (‘ training management department of the central military commission, 1), (‘ the people’s liberation army military rockets’, 1), (‘ the people’s liberation army in lanzhou military region, 1), (‘ qinghai province education department, 1), (‘ shizuishan of ningxia hui autonomous region people’s government, 1), (‘ g kyzyl Su Keer g kyrgyz autonomous prefecture people’s government ‘, 1), (‘ Education Department of Xinjiang Uygur Autonomous Region ‘, 1)

That’s it. Thanks for watching. Follow me for more Python highlights and click on the resources below to get them.

① Part-time exchange and industry consultation

②Python development environment installation tutorial

③Python self-study video

④ Big guy online professional answers

⑤Python learning roadmap

⑥ More than 300 Python e-books