pysetdf
 pysetdf | 
   
  Purpose
 
  
  Synopsis
 
 procedure pysetdf(varname:string,input:list of array)
 procedure pysetdf(varname:string,input:list of array,labels:list of string)
 
  Arguments
 
 | 
     
     varname 
       | 
   
     
     Global Python variable name for the new DataFrame
       | 
  
| 
     
     input 
       | 
   
     
     Mosel list of arrays to be converted to the DataFrame
       | 
  
| 
     
     labels 
       | 
   
     
     Labels for the DataFrame columns
       | 
  
  Example
 
 
  In this example, two Mosel arrays with the same index sets are converted to a DataFrame. With the first call to
 pysetdf, a DataFrame is created with integer column labels and the second creates a DataFrame with string column labels.
 
 declarations
    I, J: set of integer
    Numbers: dynamic array(I, J) of integer
    Labels: dynamic array(I, J) of string
end-declarations
pyinitpandas
Numbers(1,1) := 11;    Labels(1,1) := "eleven"
Numbers(2,3) := 23;    Labels(2,3) := "twenty-three"
Numbers(4,2) := 42;    Labels(4,2) := "forty-two"
writeln("Integer column labels:")
pysetdf("df", [Numbers, Labels])
pyexec("print(df)")
pysetdf("df", [Numbers, Labels], ["number", "label"])
writeln("\nString column labels:")
pyexec("print(df)")
  Further information
 
 
 1. The first version of the procedure creates a new DataFrame with numbers as column labels and the second version uses the provided string column labels.
 
 
 2. The procedure creates or overwrites the global variable by writing the new value to the attributes of the Python
 __main__ module. If the variable name is not a valid Python variable identifier the procedure will succeed anyway and write the value to the module attributes using the name specified in
 varname.
 
 
 3. The procedure replaces previously existing global variables. It does not update or add data to existing Python structures.
 
 
 4. DataFrame conversion is supported in all module functions that accept lists of arrays. In particular, it is supported by
 pycall and the I/O
  Driver python .
 
 
  Related topics
 
  
  Module
 
 
 python3
 
