If you can't read please download the document
View
106
Download
3
Embed Size (px)
Libertando Dados Pblicoscom Ferramentas Livres
Turicas aka lvaro JustenFrum Goiano de Software Livre 201619 de novembro de 2016 - Goinia/GO
http://www.fgsl.org.br/
Turicas, prazer! =)Sigam-me os bons:
{ , , , , }
/turicas
twittergithub
youtubeslideshareinstagram
alvaro@CursoDeArduino.com.brturicas.info
https://twitter.com/turicashttps://github.com/turicashttps://youtube.com/turicashttps://slideshare.net/turicashttps://instagram.com/turicasmailto:alvaro@CursoDeArduino.com.brhttp://turicas.info/
bit.ly/rows-fgsl
http://bit.ly/rows-fgsl
Software Livre
http://www.gnu.org/
Python
http://www.python.org/
Arduino
http://www.arduino.cc/
cursodearduino.com.br
http://cursodearduino.com.br/
http://2012.pythonbrasil.org.br/
pythonquito.tk
http://www.pythonquito.tk/http://www.pythonquito.tk/
pythonic.cafe(preenche o formulrio l!)
youtube.com/c/PythonicCafe
http://pythonic.cafe/https://youtube.com/c/PythonicCafe/
generonumero.media
http://generonumero.media/
escoladedados.org
http://escoladedados.org/
E vocs?Quem trabalha com converso de dados?
Scraping, data science, ...Quem conhece/usa Python?
Nmade Digital
A Jornada
Existem softwares livres para automatizar vrias etapas dajornada.
Dados Presos
Dado aberto, porm noacessvel
O Que Eu J Fiz(manualmente)
O Que Eu Quero(semi-automaticamente)
O Que Tenho Que Fazer(mas no queria ter que fazer)
Obtendo...
Vericando...
Limpando...
Automatizar tudo que for chato
Problema EspeccoDados Tabulares
Colunas (nome e tipo)Registros (valores)
Dados TabularesFormatos Possveis
CSVHTML ("table")JSONODSSQLiteXLSXLSX...
Exemplo: CSV
csv em Pythonimport csv reader = csv.DictReader(open('tesouro-direto.csv')) # TODO: identificar dialecto CSV for row in reader: print row # todo es string =/ # TODO: crear conversin de datetime # TODO: crear conversin de date # TODO: crear conversin decimal # TODO: crear conversin percent
JSON
json em Pythonimport json reader = json.load(open('tesouro-direto.csv')) for row in reader: print row # nem todo convertido =/ # TODO: crear conversin de datetime # TODO: crear conversin de date # TODO: crear conversin decimal # TODO: crear conversin percent
XLS
xls em Python + xlrdpip install xlrd
import xlrd filename = 'tesouro-direto.xls' book = xlrd.open_workbook(filename, formatting_info=True) sheet = book.sheet_by_index(0) NUMERO_DE_COLUNAS = 7 # WTF? header = [sheet.cell(0, col).value for col in range(NUMERO_DE_COLUNASNUMERO_DE_LINEAS = 19 # WTF? data = [[sheet.cell(row, col).value for col in range(NUMERO_DE_COLUNAS for row in range(1, NUMERO_DE_LINEAS + 1)] for row_data in data: row = dict(zip(header, row_data)) print row # TODO: crear conversin de date y datetime # TODO: crear conversin de decimal # TODO: crear conversin de percent
Resultado...{u'preco_compra': 0.0, u'timestamp': 42314.73819444444, u'vencimento'
Que porra essa?
..., u'timestamp': 42314.73819444444, ...
Vida Real..."Me mandaram o CSV, mas veio sem o cabealho""Esse campo no est batendo""Porque tem tanto NULL?"...
ProblemasFormatos no possuem as mesmas funcionalidadesFalta controle de qualidade na hora de publicar os dadosBibliotecas para cada formato so muito diferentes
Resultado:Perda de tempo em uma atividade que no
seu objetivo
rows to the rescue!pip install rows # Python Package Index
apt-get install rows # Debian
dnf install rows # Fedora
github.com/turicas/rows
https://github.com/turicas/rows
rowsBiblioteca PythonCommand-Line InterfacePlugins:
CSVJSONHTML (+ XPath)TXTXLSXLSXSQLiteODSParquet(+ outros em desenvolvimento)
csv com Python + rowsimport rows table1 = rows.import_from_csv('tesouro-direto.csv') for row in table1: print row
Row(timestamp=datetime.datetime(2015, 11, 6, 17, 43), titulo=u'Tesouro IPCA+ com Juros Semestrais 2017 (NTNB)', vencimento=datetime.date(2017, 5, 15), taxa_compra=Decimal('0.0702'), taxa_venda=Decimal('0.063'), preco_compra=0.0, preco_venda=2792.97) # namedtuple #FTW \o/
xls com Python + rowsimport rows table2 = rows.import_from_xls('tesouro-direto.xls') for row in table2: print row
html com Python + rowsimport rows table3 = rows.import_from_html('tesouro-direto.html') for row in table3: print row
import rows
rows: FuncionalidadesInterface nica (no importa o formato)Escrever to fcil quanto ler (pythonic way)Vrios pluginsCLIConverso automtica de dadosEu j z os testes
Command-Line Interfaceprint: mostra a tabela em formato textoconvert: converte entre os formatos suportadossum: agrega tabelasjoin: cruza dadosquery: SQL!
Live coding (CLI)
Alguns Casos de UsoCLI:
Download, converso e limpezaAnlises preliminares
Biblioteca:Converso e limpeza (exemplo: Interlegis)Converso e anlise (exemplos: sci, sl_talks)
github.com/turicas/rows
https://github.com/turicas/rows
Curso de Python Online eGratuito!
pythonic.cafe
http://pythonic.cafe/
?
Obrigado! (:Turicas aka lvaro Justen
{ , , , , }
/turicas
twittergithub
youtubeslideshareinstagram
alvaro@CursoDeArduino.com.brturicas.info
bit.ly/rows-fgsl
https://twitter.com/turicashttps://github.com/turicashttps://youtube.com/turicashttps://slideshare.net/turicashttps://instagram.com/turicasmailto:alvaro@CursoDeArduino.com.brhttp://turicas.info/http://bit.ly/rows-fgsl