I have a code in Python that does the following: Extract multiple table data into distinct excels and perform a linear regression between them. So far so good but how do I make my results clean in a TXT, excel or word file? Thanks
Here's my simplified code as there's a lot more data:
import numpy as np
import numpy as np
import pandas as pd
import plotly as py
import matplotlib.pyplot as plt
import statsmodels.api as sm
import statsmodels.formula.api as smf
# Carrega a taxa de cambio em Dólares por Real
CAMBIO = pd.read_csv("CAMBIO.csv", parse_dates=["DATE"], index_col="DATE", na_values=".")
CAMBIO['USREAL'] = pd.to_numeric(CAMBIO['USREAL'])
CAMBIO['USREAL'] = CAMBIO.USREAL.shift().apply(np.log) - pd.to_numeric(CAMBIO['USREAL']).apply(np.log)
CAMBIO.columns = ["ReturnsCAMBIO"]
CAMBIO = CAMBIO.asfreq('B')
CAMBIO = CAMBIO.reset_index()
# INICIO DA SEQUENCIA de REGRESSOES
#REGRESSAO DE BBAS3
BBAS3 = pd.read_csv("BBAS3.csv", parse_dates=["Date"], index_col="Date",
na_values="null")
BBAS3.drop(["Open", "High", "Low", "Adj Close", "Volume"], axis=1, inplace=True)
BBAS3['Close'] = BBAS3.Close.shift().apply(np.log) -
pd.to_numeric(BBAS3['Close']).apply(np.log)
BBAS3 = BBAS3.interpolate()
BBAS3.columns = ["ReturnsBBAS3"]
BBAS3 = BBAS3.asfreq('B')
BBAS3 = BBAS3.reset_index()
BBAS3 = BBAS3.dropna(axis=0, how='any')
#CONCATENAMOS NA MATRIZ SENSIBILIDADE BBAS3
sensitivityBBAS3 = pd.concat([CAMBIO, BBAS3], axis=1)
sensitivityBBAS3 = sensitivityBBAS3.dropna(axis=0, how='any')
#REALIZAMOS A REGRESSAO COM TODOS FATORES BBAS3
y = sensitivityBBAS3['ReturnsBBAS3']
X = sensitivityBBAS3[["ReturnsCAMBIO"]]
RegressionBBAS3 = sm.OLS(y, X).fit()
print(RegressionBBAS3.summary())
I wanted this sum of RegressionBBAS3 to be exported to txt or excel or word.