Skip to content

Instantly share code, notes, and snippets.

View sillasgonzaga's full-sized avatar

Sillas Teixeira Gonzaga sillasgonzaga

View GitHub Profile
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
)
# 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()
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'])
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)
# 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")
#
library(tidyverse)
library(jsonlite)
library(UpSetR)
#### imdb data ####
# Fonte: https://www.imdb.com/interfaces/
imdb_title_akas <- read_delim("data/imdb/title.akas.tsv.gz",
delim = "\t",
na = c("", "\\N"))
library(rvest)
library(stringr)
url_zap <- 'https://www.zapimoveis.com.br/aluguel/apartamentos/sp+sao-paulo/?__zt=ad:a'
xml2::read_html("https://www.zapimoveis.com.br/")
html_obj <- httr::GET(url_zap) %>%
read_html()
# http://r-br.2285057.n4.nabble.com/R-br-Ler-MAP-no-R-Shapefile-td4661880.html
# http://www2.datasus.gov.br/DATASUS/tabwin/DocTabWin.htm
# http://datasus.saude.gov.br/versao-3
# http://www2.datasus.gov.br/DATASUS/tabwin/rx/Importa_mapa.htm
# http://datasus.saude.gov.br/cadastros-nacionais/294-download-mapas-tabwin
read.map = function(filename){
zz=file(filename,"rb")
#
@sillasgonzaga
sillasgonzaga / api_quotas_fundos.R
Last active June 15, 2023 13:17
API para baixar quotas de fundos
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") %>%
# adaptacao da planilha de valuation da proseek
library(dplyr)
library(purrr)
library(magrittr)
#### párametros unicos
taxa_impostos_indiretos <- 14.65/100
margem_estimada <- 19.78/100
taxa_ir_base <- 8/100