Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Python write result of VAR to excel file wissam1974 Programmer named Tim Posts: 19 Threads: 8 Joined: Jan 2019 Reputation: 0 Likes received: 0 #1 Jul-12-2019, 11:50 PM Hi for all, i am working on creation of model VAR(Vector Auto Regressive) using python. here is the pseudo code ```model = VAR(MyDataFrame) results = model.fit(maxlags=7, method='ols', ic='aic', trend='c', verbose=False) res2=results.summary() print(res2) print(type(res2)) exit() ```the result that i have got is shown below: ``````Output: Summary of Regression Results ================================== Model: VAR Method: OLS Date: Sat, 13, Jul, 2019 Time: 02:39:36 -------------------------------------------------------------------- No. of Equations: 10.0000 BIC: 18.5402 Nobs: 4010.00 HQIC: 17.8205 Log likelihood: -91127.2 FPE: 3.69610e+07 AIC: 17.4253 Det(Omega_mle): 3.10114e+07 -------------------------------------------------------------------- Results for equation TMIN ========================================================================== coefficient std. error t-stat prob -------------------------------------------------------------------------- const 51.900181 10.849815 4.784 0.000 L1.TMIN 0.283955 0.037289 7.615 0.000 L1.TMAX 0.352748 0.032167 10.966 0.000 ... Results for equation TMAX ========================================================================== coefficient std. error t-stat prob -------------------------------------------------------------------------- const 11.231979 17.159595 0.655 0.513 L1.TMIN 0.061324 0.058975 1.040 0.298 L1.TMAX 0.892760 0.050875 17.548 0.000 L1.UMIN 0.079147 0.013430 5.893 0.000 ..... #result of print(type(res2)) is: ````````````Error: my problem is how can i write the above result to excel file??i tried to google my problem but unfortunately i did not found an appropriate solution so any help will be appreciated. ``````Thank you in advance. Skaperen So-and-so of the Yard Posts: 2,915 Threads: 900 Joined: Sep 2016 Reputation: 11 Likes received: 93 #2 Jul-13-2019, 02:09 AM you can find 92 pages worth of packages starting here. What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American. wissam1974 Programmer named Tim Posts: 19 Threads: 8 Joined: Jan 2019 Reputation: 0 Likes received: 0 #3 Jul-13-2019, 06:29 AM Hi Mr, i checked the link you have sent but i did not found what i am looking for, do you please help me find the one that fit my situation which is write the result of "write output of var.fit.summary to excel file or CSV file" thank you. perfringo Giant Foot Posts: 989 Threads: 3 Joined: Jun 2018 Reputation: 101 Likes received: 232 #4 Jul-13-2019, 07:33 AM Maybe I don't comprehend the whole picture but there is input-output library of statsmodel - iolib Quote:Users can also leverage the powerful input/output functions provided by pandas.io. Among other things, pandas (a statsmodels dependency) allows reading and writing to Excel, CSV, and HDF5 (PyTables). I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy Life of Brian: Conjugate the verb, "to go" ! wissam1974 Programmer named Tim Posts: 19 Threads: 8 Joined: Jan 2019 Reputation: 0 Likes received: 0 #5 Jul-13-2019, 08:11 AM (Jul-13-2019, 07:33 AM)perfringo Wrote: Maybe I don't comprehend the whole picture but there is input-output library of statsmodel - iolib Quote:Users can also leverage the powerful input/output functions provided by pandas.io. Among other things, pandas (a statsmodels dependency) allows reading and writing to Excel, CSV, and HDF5 (PyTables). Hi Mr, first i would like to thank you for you help. i checked the link that you had sent, and i make some modifications on my code so as it becomes as follow: ```import pandas as pd from statsmodels.tsa.base.datetools import dates_from_str import numpy as np from statsmodels.tsa.api import VAR, DynamicVAR import matplotlib.pyplot as plt import statsmodels.api as sm from statsmodels.iolib.table import SimpleTable data_NO_nan_neg=dta[ ['TMIN','TMAX','UMIN', 'UMAX','DD','FF' ,'RR' , 'TD','PS', 'PM'] ] model =sm.tsa.VAR(data_NO_nan_neg) results = model.fit(maxlags=7, method='ols', ic='aic', trend='c', verbose=False) res2=results.summary() results_as_csv=res2.tables[0].as_csv() ```i re-run the model and i am getting the following error: ``````Error: results_as_csv=res2.tables[0].as_csv() AttributeError: 'VARSummary' object has no attribute 'tables' ``````can you please help me to overpass this error. Thank you a lot Mr. perfringo Giant Foot Posts: 989 Threads: 3 Joined: Jun 2018 Reputation: 101 Likes received: 232 #6 Jul-13-2019, 08:42 AM I don't use this module therefore my advice is general one. Error message clearly states that "'VARSummary' object has no attribute 'tables'". You can't apply this method to this object. From the iolib page you can find this (maybe it helps). Quote:summary.Summary() class to hold tables for result summary presentation You can try the brute-force approach (I have no idea will it work): write the whole VARSummary object to csv, read this csv into pandas dataframe and extract tables needed, then write tables into Excel. I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy Life of Brian: Conjugate the verb, "to go" ! wissam1974 Programmer named Tim Posts: 19 Threads: 8 Joined: Jan 2019 Reputation: 0 Likes received: 0 #7 Jul-13-2019, 08:50 AM (Jul-13-2019, 08:42 AM)perfringo Wrote: I don't use this module therefore my advice is general one. Error message clearly states that "'VARSummary' object has no attribute 'tables'". You can't apply this method to this object. From the iolib page you can find this (maybe it helps). Quote:summary.Summary() class to hold tables for result summary presentation You can try the brute-force approach (I have no idea will it work): write the whole VARSummary object to csv, read this csv into pandas dataframe and extract tables needed, then write tables into Excel. Ok Mr, but this is the main issue how can write the whole VARSummary object to csv, if i make it i can then proceed to others steps, how can write the whole VARSummary object to csv? thank you scidam Posts: 541 Threads: 1 Joined: Mar 2018 Reputation: 71 Likes received: 76 #8 Jul-13-2019, 11:52 AM As it could be seen from VARSummary source code, this class doesn't have `.as_csv` method (iolib includes classes with such method). Also, it has no other methods related with csv-creation. I am not sure completely, but it seems that the best method to do what you want is to inspect your model object and find all needed coefficients. Model object includes all data you need (e.g. `model.aic` etc). You can built your own container, e.g. a data frame of these values and write this data-frame to csv. wissam1974 Programmer named Tim Posts: 19 Threads: 8 Joined: Jan 2019 Reputation: 0 Likes received: 0 #9 Jul-13-2019, 01:09 PM Hi Mr but how can i find all needed coefficients and how can i built my own container?? can you give me more details?? in fact i tried several trials such as ```data_NO_nan_neg=mdata.replace(np.inf, np.nan).replace(-np.inf, np.nan).dropna() model =sm.tsa.VAR(data_NO_nan_neg) results = model.fit(maxlags=7, method='ols', ic='aic', trend='c', verbose=False) res2=results.summary() #print(res2) print(type(res2)) res3=results.summary.Summary() results_as_csv=SimpleTable.as_csv(res2) results_as_csv=statsmodels.iolib.summary.Summary.as_csv(res2) results_as_csv=statsmodels.iolib.summary.Summary(results, 'test.csv') print(results_as_csv) res_all = [] results=res2 for res in results: low, upp = res.confint().T # unpack columns res_all.append(np.concatenate(([res.llf], res.params, res.tvalues, res.pvalues, low, upp))) ```unfortunately i did not solve my problem!! I will be very thankful if you give me more details to solve this complexity. Thank you « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post [split] Converting excel file to txt file unexceptionalhobby 2 135 Oct-16-2019, 06:34 PM Last Post: unexceptionalhobby Read exel with merged cells and write to another excel SriMekala 0 414 Aug-10-2019, 07:14 AM Last Post: SriMekala how read and write merged cells in excel SriMekala 1 451 Aug-07-2019, 11:27 PM Last Post: scidam How to add a dataframe to an existing excel file wendysling 2 1,751 May-09-2019, 07:00 PM Last Post: wendysling Import Excel File that Starts with Number kiki1113 1 541 Dec-20-2018, 07:13 PM Last Post: Larz60+ Copy raw data in excel to another new excel file keerthiprashanth 5 699 Oct-20-2018, 10:13 AM Last Post: volcano63 Write specific rows from pandas dataframe to csv file pradeepkumarbe 3 833 Oct-18-2018, 09:33 PM Last Post: volcano63 Pandas - Write to Exisitng Excel File - Sorted List dj99 4 2,720 Jul-29-2018, 07:56 AM Last Post: dj99 How do I write a line of code into an excel spreadsheet using Python code? Emerogork 2 860 Feb-07-2018, 06:54 PM Last Post: snippsat Converting excel file to txt file muhsin 3 8,756 Oct-13-2017, 07:52 PM Last Post: nilamo

Forum Jump:

Users browsing this thread: 1 Guest(s)