%pylab inline
import matplotlib.pyplot as plt
#import matplotlib
#matplotlib.style.use('ggplot') ## gnuplot style
import numpy as np
import pandas as pd
#size
width, height=12,8
plt.rcParams['figure.figsize'] = width, height #aggiunta pt
#precision in tables
pd.set_option('precision',2)
#rows in tables
pd.set_option('display.max_rows', 1000)
# this is used for regression below; install (via pip) statsmodels and patsy
import statsmodels.formula.api as sm
# to chose a csv file in the current folder
import os
filesHere=os.listdir("./")
selected=[]
for i in range(len(filesHere)):
if filesHere[i].find('_ts.csv')>0: selected.append(filesHere[i])
for i in range(len(selected)):
print (i, selected[i])
num=int(input("Choose a file via its number (>=0;<="+str(len(selected)-1)+" "))
par_df = pd.read_csv(selected[num][:17]+'_par.csv')
par_df.index += 1
ts_df = pd.read_csv(selected[num])
#set index to start from 1, data are collected at the end of each period
ts_df.index += 1
str_df = pd.read_csv(selected[num][:17]+'_str.csv')
#leave index to start from 0, data are collected at the beginning of each period
*Parameters*
par_df.astype(str,errors='ignore')
*Time series, data collected at the end of each period*
ts_df
ts_df.describe()
ts_df.corr(method="pearson").style.format("{:.2}")
result = sm.ols(formula="totalProfit ~ price + wage + totalProduction + unemployed", \
data=ts_df).fit()
print (result.summary())
*Structural infos, data collected at the beginning of each period*
str_df
myPlot = ts_df.plot(secondary_y=['price','wage'],
style=['2-','+:','^-','.:','|-','4:'],color=["OrangeRed","LawnGreen","Blue","Violet","Gray","Brown"])
myPlot.set_ylabel('unemployed, totalProfit, totalProduction, plannedProduction')
myPlot.right_ax.set_ylabel('price, wage')
myPlot.legend(loc='upper left') #, bbox_to_anchor=(-0.35, 0.5)
myPlot.axes.right_ax.legend(loc='lower right') #, bbox_to_anchor=(1.1, 0.5)
# within style the sequence is marker+style as codes at
# http://matplotlib.org/1.4.1/api/axes_api.html#matplotlib.axes.Axes.plot
# looking for
# 'The following format string characters are accepted to control the line style or marker:'
# look also to
# https://matplotlib.org/examples/lines_bars_and_markers/marker_reference.html
# but not all the combination are working
str_df.plot(secondary_y='workers',style=['^-','.-.'],color=["r","b"])
# within style the sequence is marker+style as codes at
# http://matplotlib.org/1.4.1/api/axes_api.html#matplotlib.axes.Axes.plot
# looking for
# 'The following format string characters are accepted to control the line style or marker:'
# look also to
# https://matplotlib.org/examples/lines_bars_and_markers/marker_reference.html
# but not all the combination are working
Best solutions to produce a LaTeX table from these data (the example is related to ts_df.corr table):
corr=ts_df.corr(method='pearson')
print corr.to_latex()
"print" to have the output nicely formatted; copy and paste it to LaTeX and the
result works.
To use caption and label with tabular simply include that output within:
\begin{table}
output above
\label{a label}
\caption{a caption}
\end{table}
You can add the usual [htbp] specification as \begin{table}[htbp]
Other solutions:
corr=ts_df.corr(method='pearson')
print (corr.to_latex())