# 必要なデータベースをインポートします
import json #json形式の処理
import jsonpath #jsonデータの処理
import requests #ライブラリをリクエスト
from pyecharts.charts import Map,Geo #図
from pyecharts import options as opts #構成アイテムのインポート
from pyecharts.globals import GeoType, RenderType #構成アイテムのインポート
# 1. 宛先URL
url='https://api.inews.qq.com/newsqa/v1/automation/foreign/country/ranklist'
# 2. リソースをリクエストする
resp=requests.post(url)
# print(resp.text)
# マッピング用の流行データと一致する全国辞書を確立する
nameMap={"Somalia":"ソマリア","Liechtenstein":"リヒテンシュタイン","Morocco":"モロッコ","W. Sahara":"西サハラ","Serbia":"セルビア","Afghanistan":"アフガニスタン","Angola":"アンゴラ","Albania":"アルバニア","Andorra":"アンドラ","United Arab Emirates":"アラブ首長国連邦","Argentina":"アルゼンチン","Armenia":"アルメニア","Australia":"オーストラリア","Austria":"オーストリア","Azerbaijan":"アゼルバイジャン","Burundi":"ブルンディ","Belgium":"ベルギー","Benin":"ベニン","Burkina Faso":"ブルキナファソ","Bangladesh":"バングラデシュ","Bulgaria":"ブルガリア","Bahrain":"バーレーン","Bahamas":"バハマ","Bosnia and Herz.":"ボスニア・ヘルツェゴビナ","Belarus":"ベラルーシ","Belize":"ベリーズ","Bermuda":"バミューダ","Bolivia":"ボリビア","Brazil":"ブラジル","Barbados":"バルバドス","Brunei":"ブルネイ","Bhutan":"ブータン","Botswana":"ボツワナ","Central African Rep.":"中央アフリカ","Canada":"カナダ","Switzerland":"スイス","Chile":"チリ","China":"中国","Côte d'Ivoire":"Coted'Ivoire","Cameroon":"カメルーン","Dem. Rep. Congo":"コンゴ民主共和国","Congo":"コンゴ","Colombia":"コロンビア","Cape Verde":"ケープヴェルデ","Costa Rica":"コスタリカ","Cuba":"キューバ","N. Cyprus":"北キプロス","Cyprus":"キプロス","Czech Rep.":"チェコ共和国","Germany":"ドイツ","Djibouti":"ジブチ","Denmark":"デンマーク","Dominican Rep.":"ドミニカ","Algeria":"アルジェリア","Ecuador":"エクアドル","Egypt":"エジプト","Eritrea":"エリトリア","Spain":"スペイン","Estonia":"エストニア","Ethiopia":"エチオピア","Finland":"フィンランド","Fiji":"フィジー","France":"フランス","Gabon":"ガボン","United Kingdom":"イギリス","Georgia":"ジョージア","Ghana":"ガーナ","Guinea":"ギニア","Gambia":"ガンビア","Guinea-Bissau":"ギニア比绍","Eq. Guinea":"赤道ギニア","Greece":"ギリシャ","Grenada":"グレナダ","Greenland":"グリーンランド","Guatemala":"グアテマラ","Guam":"グアム","Guyana":"ガイアナ","Honduras":"ホンジュラス","Croatia":"クロアチア","Haiti":"ハイチ","Hungary":"ハンガリー","Indonesia":"インドネシア","India":"インド","Br. Indian Ocean Ter.":"英属インド洋领土","Ireland":"アイルランド","Iran":"イラン","Iraq":"イラク","Iceland":"アイスランド","Israel":"イスラエル","Italy":"イタリア","Jamaica":"ジャマイカ","Jordan":"ヨルダン","Japan":"日本","Siachen Glacier":"シアチェン氷河","Kazakhstan":"カザフスタン","Kenya":"ケニア","Kyrgyzstan":"キルギスタン","Cambodia":"カンボジア","Korea":"韓国","Kuwait":"クウェート","Lao PDR":"ラオス","Lebanon":"レバノン","Liberia":"リベリア","Libya":"リビア","Sri Lanka":"スリランカ","Lesotho":"レソト","Lithuania":"リトアニア","Luxembourg":"ルクセンブルク","Latvia":"ラトビア","Moldova":"モルドバ","Madagascar":"マダガスカル","Mexico":"メキシコ","Macedonia":"マケドニア","Mali":"マリ","Malta":"マルタ","Myanmar":"ミャンマー","Montenegro":"モンテネグロ","Mongolia":"モンゴル","Mozambique":"モザンビーク","Mauritania":"モーリタニア","Mauritius":"モーリシャス","Malawi":"マラウィ","Malaysia":"マレーシア","Namibia":"ナミビア","New Caledonia":"ニューカレドニア","Niger":"ニジェール","Nigeria":"ナイジェリア","Nicaragua":"ニカラグア","Netherlands":"オランダ","Norway":"ノルウェー","Nepal":"ネパール","New Zealand":"ニュージーランド","Oman":"オマーン","Pakistan":"パキスタン","Panama":"パナマ","Peru":"ペルー","Philippines":"フィリピン","Papua New Guinea":"巴布亚新ギニア","Poland":"ポーランド","Puerto Rico":"プエルトリコ","Dem. Rep. Korea":"韓国","Portugal":"ポルトガル","Paraguay":"パラグアイ","Palestine":"パレスチナ","Qatar":"カタール","Romania":"ルーマニア","Russia":"ロシア","Rwanda":"ルワンダ","Saudi Arabia":"サウジアラビア","Sudan":"スーダン","S. Sudan":"南スーダン","Senegal":"セネガル","Singapore":"シンガポール","Solomon Is.":"ソロモン諸島","Sierra Leone":"シエラレオネ","El Salvador":"サルバドール","Suriname":"スリナメ","Slovakia":"スロバキア","Slovenia":"スロベニア","Sweden":"スウェーデン","Swaziland":"スワジランド","Seychelles":"セイシェル","Syria":"シリア","Chad":"チャド","Togo":"トーゴ","Thailand":"タイ","Tajikistan":"タジキスタン","Turkmenistan":"トルクメニスタン","Timor-Leste":"東ティモール","Tonga":"トンガ","Trinidad and Tobago":"トリニダード・トバゴ","Tunisia":"チュニジア","Turkey":"七面鳥","Tanzania":"タンザニア","Uganda":"ウガンダ","Ukraine":"ウクライナ","Uruguay":"ウルグアイ","United States":"アメリカ","Uzbekistan":"ウズベキスタン","Venezuela":"ベネズエラ","Vietnam":"ベトナム","Vanuatu":"バヌアツ","Yemen":"イエメン","South Africa":"南アフリカ","Zambia":"ザンビア","Zimbabwe":"ジンバブエ","Aland":"アランド諸島","American Samoa":"アメリカのサモア","Fr. S. Antarctic Lands":"南極大陸","Antigua and Barb.":"アンティグアとバルブダ","Comoros":"コモロス","Curaçao":"キュラソー","Cayman Is.":"ケイマン諸島","Dominica":"ドミニカ","Falkland Is.":"マルビナス諸島(フォークランド)","Faeroe Is.":"フェロー諸島","Micronesia":"ミクロネシア","Heard I. and McDonald Is.":"聞いた島とマクドナルド諸島","Isle of Man":"マン島","Jersey":"ジャージー","Kiribati":"キリバティ","Saint Lucia":"セントルシア","N. Mariana Is.":"北マリ亚纳群岛","Montserrat":"モントセラト","Niue":"ニウエ","Palau":"パラウ","Fr. Polynesia":"フランス領ポリネシア","S. Geo. and S. Sandw. Is.":"サウスジョージアとサウスサンドイッチ諸島","Saint Helena":"セントヘレナ","St. Pierre and Miquelon":"サンピエールとミケロン","São Tomé and Principe":"サントメとプリンシペ","Turks and Caicos Is.":"トルコ人とカイコス諸島","St. Vin. and Gren.":"セントビンセントとグレナディーン","U.S. Virgin Is.":"アメリカ合衆国バージン諸島","Samoa":"サモア"}
# 3. データを抽出する
data=json.loads(resp.text)
name=jsonpath.jsonpath(data,"$..name")
confirm=jsonpath.jsonpath(data,"$..confirm")
# print(name)
# print(confirm)
# データベースを構築する
data_list=zip(name,confirm)#2列のデータを組み合わせる
print(data_list)
# 視覚化
map=Map(opts.InitOpts(width='1600px',height='900px')).add(series_name="世界流行マップ",
data_pair=list(data_list),
maptype="world",
name_map=nameMap,
is_map_symbol_show=False)
# セットアップ図
map.set_series_opts(label_opts=opts.LabelOpts(is_show=False))#国名を表示しない
map.set_global_opts(title_opts=opts.TitleOpts(title="世界の流行"),#タイトルを設定
visualmap_opts=opts.VisualMapOpts(max_=10000000,is_piecewise=True))#凡例を設定し、患者数に応じて色を描きます
map.render("世界の流行の分布.html")#結果を保存
ついに構成されたjupyternotebook、とても幸せ。
Recommended Posts