Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. Sub save_rt()
  2. Dim lc As MSScriptControl.ScriptControl
  3. Set lc = New MSScriptControl.ScriptControl
  4. lc.Language = "python"
  5. lc.Timeout = 50000 'in sec
  6. workingdir = Range("xmldir").Cells.Value
  7. lc.ExecuteStatement ("import pandas as pd")
  8. lc.ExecuteStatement ("import numpy as np")
  9. lc.ExecuteStatement ("import gc")
  10.  
  11. myvalues = Range("icap_cf_values").Cells
  12. n_righe = UBound(myvalues)
  13. n_colonne = UBound(myvalues, 2)
  14. lc.ExecuteStatement ("myvalues = []")
  15. For i = 1 To n_righe
  16. For j = 1 To n_colonne
  17. If VarType(myvalues(i, j)) = vbString Then
  18. lc.ExecuteStatement ("myvalues.append('" + myvalues(i, j) + "')")
  19. Else
  20. lc.ExecuteStatement ("myvalues.append('" + Str(myvalues(i, j)) + "')")
  21. End If
  22. Next j
  23. Next i
  24. lc.ExecuteStatement ("myvalues = np.array([item for item in myvalues])")
  25. lc.ExecuteStatement ("myvalues = myvalues.reshape(" + Str(n_righe) + "," + Str(n_colonne) + ")")
  26. myindex = Range("icap_cf_mats").Cells
  27. lc.ExecuteStatement ("myindex = []")
  28. For Each d In myindex
  29. lc.ExecuteStatement ("myindex.append('" + d + "')")
  30. Next
  31. mycolumns = Range("icap_cf_cols").Cells
  32. lc.ExecuteStatement ("mycolumns = []")
  33. For Each d In mycolumns
  34. lc.ExecuteStatement ("mycolumns.append('" + d + "')")
  35. Next
  36. lc.ExecuteStatement ("rt = pd.DataFrame(myvalues,index=myindex,columns=mycolumns)")
  37.  
  38. A = lc.Eval("rt.to_csv('" + workingdir + "\fwd_cfs.csv')")
  39.  
  40. lc.ExecuteStatement ("del rt, myvalues, mycolumns")
  41. lc.ExecuteStatement ("gc.collect()")
  42. Set myindex = Nothing
  43. Set mcolumns = Nothing
  44. Set myvalues = Nothing
  45. Set n_righe = Nothing
  46. Set n_colonne = Nothing
  47. Set A = Nothing
  48. Set workingdir = Nothing
  49. Set lc = Nothing
  50.  
  51. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement