Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub save_rt()
- Dim lc As MSScriptControl.ScriptControl
- Set lc = New MSScriptControl.ScriptControl
- lc.Language = "python"
- lc.Timeout = 50000 'in sec
- workingdir = Range("xmldir").Cells.Value
- lc.ExecuteStatement ("import pandas as pd")
- lc.ExecuteStatement ("import numpy as np")
- lc.ExecuteStatement ("import gc")
- myvalues = Range("icap_cf_values").Cells
- n_righe = UBound(myvalues)
- n_colonne = UBound(myvalues, 2)
- lc.ExecuteStatement ("myvalues = []")
- For i = 1 To n_righe
- For j = 1 To n_colonne
- If VarType(myvalues(i, j)) = vbString Then
- lc.ExecuteStatement ("myvalues.append('" + myvalues(i, j) + "')")
- Else
- lc.ExecuteStatement ("myvalues.append('" + Str(myvalues(i, j)) + "')")
- End If
- Next j
- Next i
- lc.ExecuteStatement ("myvalues = np.array([item for item in myvalues])")
- lc.ExecuteStatement ("myvalues = myvalues.reshape(" + Str(n_righe) + "," + Str(n_colonne) + ")")
- myindex = Range("icap_cf_mats").Cells
- lc.ExecuteStatement ("myindex = []")
- For Each d In myindex
- lc.ExecuteStatement ("myindex.append('" + d + "')")
- Next
- mycolumns = Range("icap_cf_cols").Cells
- lc.ExecuteStatement ("mycolumns = []")
- For Each d In mycolumns
- lc.ExecuteStatement ("mycolumns.append('" + d + "')")
- Next
- lc.ExecuteStatement ("rt = pd.DataFrame(myvalues,index=myindex,columns=mycolumns)")
- A = lc.Eval("rt.to_csv('" + workingdir + "\fwd_cfs.csv')")
- lc.ExecuteStatement ("del rt, myvalues, mycolumns")
- lc.ExecuteStatement ("gc.collect()")
- Set myindex = Nothing
- Set mcolumns = Nothing
- Set myvalues = Nothing
- Set n_righe = Nothing
- Set n_colonne = Nothing
- Set A = Nothing
- Set workingdir = Nothing
- Set lc = Nothing
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement