Interoperability of Mojo Programming Language with Python Ecosystem: Using Pandas Python Data Analysis and Manipulation Library by reading a Comma Separated Values (CSV) file into Dataframe in Mojo Programming Language

Shriram Sivanandhan
4 min readNov 17, 2023

--

Mojo Programming Language combines the usability of Python with the performance of C, C++ and Rust. Mojo Programming Language utilizes next-generation compiler technologies with features like caching, multithreading and cloud distribution technologies. Further, Auto-Tuning and compile-time Metaprogramming features allows to write code for several hardware. The advantages of Mojo Programming Language are Usability & Programmability, best performance, Interoperability and Extensibility.

In this Article/Blog, we are going to see the Interoperability of Mojo Programming Language with Python Ecosystem to use Pandas Python Data Analysis and Manipulation Library by reading a Comma Separated Values (CSV) file into Dataframe in Mojo Programming Language. In this Article/Blog, we are going to see how to read a Comma Separated Values (CSV) file into Dataframe we use pandas.read_csv() function and to print information about a DataFrame / concise summary of a DataFrame we use Pandas DataFrame.info() function.

In this Blog, Programming in Mojo is done using Mojo Playground.

Interoperability of Mojo Programming Language with Python Ecosystem:

In Mojo Programming Language, Interoperability with Python Ecosystem can be done to import Python modules / libraries / custom code / local modules and use it with Mojo Programming and also to create Python types from Mojo types. This mechanism uses CPython Interpreter to run the Python code and currently it works with all Python modules.

Pandas Python Data Analysis and Manipulation Library in Mojo Programming Language:

Pandas is an open-source Data Analysis and Manipulation tool, which is easy to use, flexible, fast, and powerful, built on top of the Python programming language. Pandas library offers Data structures and operations which is easy to use, flexible, fast, and powerful Data Analysis and Manipulation.

To import a Python module / library in Mojo, first we should import Python from python module / library, then we should use Python.import_module() fucntion with the required module name.

Using Pandas Python Data Analysis and Manipulation Library by reading a Comma Separated Values (CSV) file into Dataframe in Mojo Programming Language:

To read a Comma Separated Values (CSV) file into Dataframe we use pandas.read_csv() function.

Using Pandas Python Data Analysis and Manipulation Library by reading a Comma Separated Values (CSV) file into Dataframe in Mojo Programming Language
Using Pandas Python Data Analysis and Manipulation Library by reading a Comma Separated Values (CSV) file into Dataframe in Mojo Programming Language (Implementation in Mojo Playground)

To print information about a DataFrame / concise summary of a DataFrame we use Pandas DataFrame.info() function.

Using Pandas Python Data Analysis and Manipulation Library by reading a Comma Separated Values (CSV) file into Dataframe in Mojo Programming Language
Using Pandas Python Data Analysis and Manipulation Library by reading a Comma Separated Values (CSV) file into Dataframe in Mojo Programming Language (Implementation in Mojo Playground)

We read a different CSV file named Dataset.csv file into Dataframe and print information about a DataFrame / concise summary of a DataFrame using Pandas DataFrame.info() function in the below example.

Using Pandas Python Data Analysis and Manipulation Library by reading a Comma Separated Values (CSV) file into Dataframe in Mojo Programming Language
Using Pandas Python Data Analysis and Manipulation Library by reading a Comma Separated Values (CSV) file into Dataframe in Mojo Programming Language (Implementation in Mojo Playground)

Since, Mojo Programming Language is still in development some features of Python Programming Language are not yet implemented in Mojo and not a full superset of Python yet, but all the missing Python features will be implemented soon as mentioned by Modular-Mojo Development Team. But Mojo Programming Language already consists of many features and capabilities beyond Python Programming Language.

We had seen about Interoperability of Mojo Programming Language with Python Ecosystem to use Pandas Python Data Analysis and Manipulation Library by reading a Comma Separated Values (CSV) file into Dataframe in Mojo Programming Language. Programming in Mojo and Mojo Programming concepts will be discussed further. We had seen about how to read a Comma Separated Values (CSV) file into Dataframe we use pandas.read_csv() function and to print information about a DataFrame / concise summary of a DataFrame we use Pandas DataFrame.info() function.

Thankyou for reading this blog on Interoperability of Mojo Programming Language with Python Ecosystem: Using Pandas Python Data Analysis and Manipulation Library by reading a Comma Separated Values (CSV) file into Dataframe in Mojo Programming Language.

Reference:

https://docs.modular.com/mojo/programming-manual.html

https://docs.modular.com/mojo/manual/basics/

https://pandas.pydata.org/

--

--

No responses yet