This file contains hidden or 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(tidyverse) | |
# toy dataset | |
df <- tibble( | |
clientes = c('joao', 'joao', 'joao', 'lucas', 'lucas', 'julia', 'julia', 'julia', 'julia'), | |
produtos = c('celular', 'notebook', 'livro', 'bola', 'carro', 'chapéu', 'moto', 'moto', 'caneta') | |
) | |
# função customizada | |
get_produtos <- function(produtos){ |
This file contains hidden or 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
""" | |
Defining a custom function to be applied in pandas groupby | |
""" | |
import numpy as np | |
import pandas as pd | |
clients = ['joao', 'joao', 'joao', 'lucas', 'lucas', 'julia', 'julia', 'julia', 'julia'] | |
products = ['smartphone', 'notebook', 'book', 'ball', 'car', 'hat', 'bike', 'mouse', 'pen'] |
This file contains hidden or 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 re | |
my_string = "012.345.678-09" | |
digits_pattern = r"\d+" | |
digits = re.findall(digits_pattern, my_string) | |
number = int(''.join(digits)) | |
print(number) | |
# output: 1234567809 |
This file contains hidden or 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 numpy as np | |
import statsmodels.formula.api as sm | |
def backward_elimination2(X, y, sl): | |
""" | |
X: the data matrix with the independent variables (predictors) | |
y: the matrix of the dependent variable (target) | |
sl: statistical level, by default the user should add 0.05 (5%) | |
""" | |
X = np.append(arr=np.ones((len(X),1)).astype(int), values=X, axis=1) | |
This file contains hidden or 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 numpy as np | |
import statsmodels.formula.api as sm | |
def backward_elimination(X, y, sl): | |
""" | |
X: the data matrix with the independent variables (predictors) | |
y: the matrix of the dependent variable (target) | |
sl: statistical level, by default the user should add 0.05 (5%) | |
""" | |
X = np.append(arr=np.ones((len(X),1)).astype(int), values=X, axis=1) | |
while(True): |
This file contains hidden or 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 numpy as np | |
def latlon2km(latlon1,latlon2): | |
# approximate radius of earth in km | |
R = 6373.0 | |
lat1 = np.radians(latlon1[0]) | |
lon1 = np.radians(latlon1[1]) | |
lat2 = np.radians(latlon2[0]) | |
lon2 = np.radians(latlon2[1]) |
This file contains hidden or 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
% Package for subfloat | |
\usepackage{subfig} | |
% Figure with two sub-figures | |
\begin{figure} | |
\centering | |
\subfloat[caption of the figure goes here] | |
{ | |
\includegraphics[scale=.5]{fig-1.pdf} | |
\label{fig:foo-1} |
NewerOlder