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
from scipy import stats | |
k2, p = stats.normaltest(Alturas.ALTURA.values) | |
alpha = 0.05 | |
print("p = {:g}".format(p)) | |
if p < alpha: # Hipótese nula: Os dados são de uma distribuição normal | |
print("A hipótese nula pode ser rejeitada") | |
else: | |
print("A hipótese nula não pode ser rejeitada") |
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
#dataset name = data | |
# Define your investment | |
investment = 1000 | |
# Calculate the daily returns here | |
returns = data.pct_change() | |
# Calculate the cumulative returns here | |
returns_plus_one = returns + 1 | |
cumulative_return = returns_plus_one.cumprod() |
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 the module for estimating an ARMA model | |
from statsmodels.tsa.arima_model import ARMA | |
# Fit the data to an AR(p) for p = 0,...,6 , and save the BIC | |
BIC = np.zeros(7) | |
for p in range(7): | |
mod = ARMA(simulated_data_2, order=(p,0)) | |
res = mod.fit() | |
# Save BIC for AR(p) | |
BIC[p] = res.bic |
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 the statsmodels module for regression and the adfuller function | |
import statsmodels.api as sm | |
from statsmodels.tsa.stattools import adfuller | |
# Regress BTC on ETH | |
ETH = sm.add_constant(ETH) | |
result = sm.OLS(BTC,ETH).fit() | |
# Compute ADF | |
b = result.params[1] |
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
variaveis_categoricas = [] #lista de variaveis categoricas | |
variaveis_continuas = [] #lista de variaveis continuas | |
for col in variaveis_categoricas: | |
dataset[col] = dataset[col].astype('category') | |
for col in variaveis_continuas: | |
dataset[col] = dataset[col].astype('float64') #pode ser int64 |
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
dataset_encoded = dataset_raw.apply(LabelEncoder().fit_transform) |
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 glob | |
import os | |
import pandas as pd | |
path = r'/path/to/Files' | |
all_files = glob.glob(os.path.join(path, "*.csv")) | |
df = pd.concat((pd.read_csv(f, sep = ';', header = None, encoding= 'ISO-8859-1') for f in all_files)) | |
li = [] | |
for filename in all_files: |
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 pandas as pd | |
from sqlalchemy import create_engine | |
engine = create_engine('postgresql+psycopg2://USER:PASSWORD@HOST/DATABASE') | |
query = "SELECT * FROM table" | |
df = pd.read_sql_query(query,engine) |
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
campo1 = 'campo 1 do Json de request' | |
campo2 = 'campo 2 do Json de request' | |
# Dados de acesso da API | |
URL = 'https://link-da-api.app' | |
api_token = 'TOKEN DE ACESSO' | |
headers = {'Content-Type': 'application/json', | |
'Authorization': 'Bearer {0}'.format(api_token), | |
} |
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
from sqlalchemy import create_engine | |
import io | |
import pandas as pd | |
# Joga DataFrame diretamente no banco de dados | |
print("Carregando DataFrame no banco de dados...\n") | |
conn = engine.raw_connection() | |
cur = conn.cursor() | |
output = io.StringIO() |