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
library(httr) | |
library(magrittr) | |
library(xml2) | |
library(rvest) | |
url_raw <- "http://dados.cvm.gov.br/dados/FI/DOC/INF_DIARIO/DADOS/" | |
output_file <- "fundos/api/informe_diario.csv" | |
csv_links <- httr::GET(url_raw) %>% | |
httr::content("text") %>% |
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
import panel as pn # GUI | |
pn.extension() | |
def get_completion(prompt, model="gpt-3.5-turbo"): | |
messages = [{"role": "user", "content": prompt}] | |
response = openai.ChatCompletion.create( | |
model=model, | |
messages=messages, | |
temperature=0, # this is the degree of randomness of the model's output | |
) |
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
# filtrar ano mais recente | |
df_idhm = df_idhm[df_idhm['ANO'] == np.max(df_idhm['ANO'])] | |
# selecionar colunas | |
df_idhm = df_idhm[['Codmun7', 'IDHM']] | |
# renomear colunas | |
df_idhm.columns = ['cod_municipio', 'idhm'] | |
df_idhm.head() |
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
# baixar dados | |
library(tidyverse) | |
library(foreign) | |
library(readxl) | |
library(janitor) | |
library(fuzzyjoin) | |
# download.file("http://www.metro.sp.gov.br/pesquisa-od/arquivos/Pesquisa-Origem-Destino-2017-Banco-Dados.zip", | |
# destfile = "od.zip") | |
# |
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
cdb <- function(capital, data_aplicacao, data_resgate, di, pct_cdi){ | |
library(dplyr) | |
library(bizdays) | |
dias_corridos <- as.numeric(difftime(data_resgate, data_aplicacao, units = "days")) | |
# computar biz days entre datas | |
bizdays::create.calendar("Brazil/ANBIMA", | |
bizdays::holidaysANBIMA, | |
weekdays=c("saturday", "sunday")) |
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
library(tabulizer) | |
library(tidyverse) | |
arquivo <- "C:/Users/sillas.gonzaga/Downloads/gsa.pdf" | |
tab <- tabulizer::extract_tables(arquivo, encoding = "UTF-8", method = "lattice") | |
map(tab,dim) | |
# extrair tabelas com 8 colunas |
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
plot_rf_tree <- function(final_model, tree_num, shorten_label = TRUE) { | |
# source: https://shiring.github.io/machine_learning/2017/03/16/rf_plot_ggraph | |
# get tree by index | |
tree <- randomForest::getTree(final_model, | |
k = tree_num, | |
labelVar = TRUE) %>% | |
tibble::rownames_to_column() %>% | |
# make leaf split points to NA, so the 0s won't get plotted |
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
def correl_df(dframe): | |
correl_matrix = dframe.corr() | |
# Select upper triangle of correlation matrix | |
upper = correl_matrix.where(np.triu(np.ones(correl_matrix.shape), k=1).astype(np.bool)).head() | |
upper = upper.unstack().reset_index() | |
# rename columns | |
upper.columns = ['var1', 'var2', 'correl'] | |
# drop na | |
upper = upper.dropna() | |
upper['correl_abs'] = np.abs(upper['correl']) |
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
library(spotifyr) | |
library(tidyverse) | |
Sys.setenv(SPOTIFY_CLIENT_ID = '') | |
Sys.setenv(SPOTIFY_CLIENT_SECRET = '') | |
xml <- read_html("https://developer.spotify.com/documentation/general/guides/scopes/") | |
scopes <- xml %>% html_nodes("code") %>% html_text() %>% unique() | |
auth <- get_spotify_authorization_code(scope = scopes) |
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
import time | |
import sys | |
import logging | |
import pychromecast | |
from scapy.all import * | |
mac_address = '00:00:00:00:00:00' | |
def arp_display(pkt): | |
if pkt[ARP].op == 1: | |
if pkt[ARP].hwsrc == mac_address: |
NewerOlder