- Difficulty level: easy
- Time need to lean: 10 minutes or less
- Key points
- There is almost a one-to-one correspondence between Julia and Python types
- Python has one
str
type and Julia hasChar
andString
Julia's data types are pretty close to Python and there is almost a one-to-one correspondence between Julia and Python types.
When transferring data from Python (SoS) to Julia (e.g. %get
from Julia), the resulting Julia types are list as follows:
Python | condition | Julia |
---|---|---|
None |
NaN |
|
boolean |
Bool |
|
integer |
Int64 |
|
numpy.float64 |
Float64 |
|
float |
Float64 |
|
complex |
Complex{} |
|
str |
String |
|
Sequence (list , tuple , ...) |
homogenous type, all integer | Array{Int64,1} |
Sequence (list , tuple , ...) |
homogenous type, all numeric with any float | Array{Float64,1} |
Sequence (list , tuple , ...) |
homogenous type, all str | Array{String,1} |
Sequence (list , tuple , ...) |
multiple types | Array{Any,1} |
set |
homogenous type, all integer | Set{Int64} |
set |
homogenous type, all numeric with any float | Set{Float64} |
set |
homogenous type, all str | Set{String} |
set |
multiple types | Set{Any} |
dict |
Dict{} |
|
numpy.ndarray |
Array{} |
|
numpy.matrix |
Array{} |
|
pandas.Series |
NamedArrays.NamedArray{} |
|
pandas.DataFrame |
Dataframes.Dataframe{} |
Python objects in other datatypes are transferred as string "Unsupported datatype"
.
It is worth noting that although Julia supports Char
(single character) and String
types, SoS always transfer Python str
to Julia String
, so if you have a Python string X
,
If you need to access the first character as a Char
, just use
Conversion of datatypes from Julia to SoS (%get var --from Julia
from SoS) follows the following rules:
Julia | condition | Python |
---|---|---|
NaN |
None |
|
Bool |
boolean |
|
Int64 |
integer |
|
Char |
str |
|
Complex{} |
complex |
|
Float64 |
numpy.float64 |
|
String |
str |
|
Array{,1} |
Sequence ( list, tuple, ...) |
|
Set{} |
set |
|
Dict{} |
dict |
|
Array{Int64/Float64,2} |
2 dimensions | numpy.matrix |
Array{Int64/Float64,} |
> 2 dimensions | numpy.ndarray |
NamedArrays.NamedArray |
1 dimension | pandas.Series |
Dataframes.Dataframe |
pandas.DataFrame |
Julia objects in other datatypes are transferred as string "Unsupported datatype"
.
Julia supports DataFrame from its DataFrames
package so you will need to install this package before using the Julia kernel. For example, a R dataframe is transfered as Dataframes.Dataframe to Julia.
As you can see from the warning, row labels of the dataframe is not transferred because Julia's dataframe does not support row label. If you really need the row labels, you would have to assign row labels to a separate variable and transfer.
When an Julia Array
is transferred to SoS (Python3), it becomes a numpy.array
.