Transform excel file into array - python

Asked

Viewed 474 times

0

In the code below I am assigning values within the code itself, I tried to pull the values directly from excel using pd.read_excel, but I don’t know how to turn it into an array for this code to work. How could I do that?

Planilha: Dados.xlsx

import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

from statsmodels.tsa.api import ExponentialSmoothing, SimpleExpSmoothing, Holt



data = [ 370709, 807576, 1102649, 212706, 80104, 487402, 151208, 526116, 1289653, 503726, 451504, 471161, 210146, 798700, 1382556 ]

index= pd.date_range(start='2019-10', end='2020-12', freq='MS')
aust = pd.Series(data, index)

fit1 = ExponentialSmoothing(aust, seasonal_periods=3, trend='add', seasonal='add').fit(use_boxcox=True)

results=pd.DataFrame(index=[r"$\alpha$",r"$\beta$",r"$\phi$",r"$\gamma$",r"$l_0$","$b_0$","SSE"])
params = ['smoothing_level', 'smoothing_slope', 'damping_slope', 'smoothing_seasonal', 'initial_level', 'initial_slope']
results["Additive"] = [fit1.params[p] for p in params] + [fit1.sse]


ax = aust.plot(figsize=(10,6), marker='o', color='black', title="Forecasts from Holt-Winters" )
ax.set_ylabel("Volume")
ax.set_xlabel("Meses")
fit1.fittedvalues.plot(ax=ax, style='--', color='red')


fit1.forecast(8).rename('Holt-Winters (add-add-seasonal)').plot(ax=ax, style='--', marker='o', color='red', legend=True)

plt.show()

1 answer

0


import pandas as pd
import numpy as np
from pandas import ExcelWriter
from pandas import ExcelFile

df = pd.read_excel('file1.xlsx')
array  = np.asarray(df) // transformar em array

//resultado
array([[ 2, 99],
       [ 3, 98],
       [ 4, 97],
       [ 5, 95]], dtype=int64)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.