-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #577 from basedosdados/br_bd_diretorios_mundo
[dados]br_bd_diretorios_mundo.pais
- Loading branch information
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
models/br_bd_diretorios_mundo/code/[coi-fifa]br_bd_diretorios_mundo_pais.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import pandas as pd | ||
import os | ||
|
||
# Antigo arquivo de pais sem COI e FIFA | ||
original = pd.read_csv("https://storage.googleapis.com/basedosdados/staging/br_bd_diretorios_mundo/pais/pais.csv") | ||
|
||
html = 'https://pt.wikipedia.org/wiki/Compara%C3%A7%C3%A3o_entre_c%C3%B3digos_de_pa%C3%ADses_COI,_FIFA,_e_ISO_3166' | ||
|
||
attrs = {'class': 'wikitable'} | ||
|
||
dfs = pd.read_html(html, attrs=attrs, header=0) | ||
|
||
df_dif = pd.concat([df for df in dfs]) | ||
|
||
ico_fifa = df_dif[["COI", "FIFA", "ISO-3"]] | ||
ico_fifa.columns = ["sigla_pais_coi", "sigla_pais_fifa", "sigla_pais_iso3"] | ||
|
||
merge_df = original.merge(ico_fifa, left_on="sigla_pais_iso3", right_on='sigla_pais_iso3', how="left") | ||
|
||
os.makedirs("output", exist_ok=True) | ||
|
||
merge_df.to_csv("output/pais.csv", index=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandas as pd\n", | ||
"import requests\n", | ||
"from io import BytesIO\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"urls = {\n", | ||
" 'ncm' : 'https://balanca.economia.gov.br/balanca/bd/tabelas/NCM.csv',\n", | ||
" 'sh4': 'https://balanca.economia.gov.br/balanca/bd/tabelas/NCM_SH.csv'\n", | ||
" }\n", | ||
"\n", | ||
"for k in urls:\n", | ||
" print(f'Baixando tabela {k}')\n", | ||
" \n", | ||
" response = requests.get(urls[k], verify=False)\n", | ||
" if response.status_code == 200:\n", | ||
" \n", | ||
" data = BytesIO(response.content)\n", | ||
" df = pd.read_csv(data, encoding='latin-1', sep=';', dtype = str)\n", | ||
" df.to_csv(\n", | ||
" f'{k}.csv',\n", | ||
" index=False,\n", | ||
" encoding = 'utf-8',\n", | ||
" sep=',', \n", | ||
" )\n", | ||
" else:\n", | ||
" print(f'Erro! O status da requisição foi {response.status_code}')\n", | ||
"\n", | ||
" " | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "bd_pipelines", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.15" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters