- Difficulty level: easy
- Time need to lean: 10 minutes or less
- SoS replies on JSON format to convert between complex data types to and from JavaScript
SoS exchange data with a JavaScript kernel using JSON format. It passes all JSON serializable datatypes using the json
module, and convert numpy arrays to list before translation (array.tolist()
), and use DataFrame.to_jason to translate Pandas DataFrame to a list of records in JS.
Python | condition | JavaScript |
---|---|---|
None |
null |
|
boolean , int , str , etc |
corresponding JS type | |
numpy.ndarray |
array | |
numpy.matrix |
nested array | |
pandas.DataFrame |
table with scheme and array of records (dictionary) |
Translation from JavaScript to Python is easier because Python supports all JSON serializable JS datatypes.
The DataFrame translation is particularly interesting because it allows you to pass complex datatypes in Python and R for visualization. For example, for the following data.frame in R,
It appears in SoS as a pandas DataFrame
we can get the data from the JS script kernel as follows:
SoS exchange data with a JypeScript kernel using JSON format. It passes all JSON serializable datatypes using the json
module, and convert numpy arrays to list before translation (array.tolist()
), and use DataFrame.to_jason to translate Pandas DataFrame to a list of records in JS.
Python | condition | TypeScript |
---|---|---|
None |
null |
|
boolean , int , str , etc |
corresponding JS type | |
numpy.ndarray |
array | |
numpy.matrix |
nested array | |
pandas.DataFrame |
table with scheme and array of records (dictionary) |
Translation from TypeScript to Python is easier because Python supports all JSON serializable TS datatypes.
The DataFrame translation is particularly interesting because it allows you to pass complex datatypes in Python and R for visualization. For example, for the following data.frame in R,
we can get the data from the TS script kernel as follows: