Using OpenAI for Series operations
Many of the Series operations demonstrated in the previous recipes in this chapter can be assisted by AI tools, including by PandasAI, with the large language model from OpenAI. In this recipe, we examine how to use PandasAI to query Series values, create new Series, set Series values conditionally, and do some rudimentary reshaping of DataFrames.
Getting ready
We will work with the NLS and COVID-19 case daily data again in this recipe. We will also work with PandasAI, which can be installed with pip install pandasai
. You also need to get a token from openai.com to send a request to the OpenAI API.
How to do it...
The following steps create a PandasAI SmartDataframe
object, and then use the chat method of that object to submit natural language instructions for a range of Series operations:
- We first need to import the
OpenAI
andSmartDataframe
modules from PandasAI. We also have to instantiate anllm
object:import...