How I use Leo AI as a Coding Assistant / Consultant for Data Analysis

How I use Leo AI as a Coding Assistant / Consultant for Data Analysis

If words of command are not clear and distinct, if orders are not thoroughly understood, then the general is to blame. But, if orders are clear and the soldiers nevertheless disobey, then it is the fault of their officers.”

Tsun-Tzu


This post proposes to demonstrate by example how to seamlessly integrate Leo AI in data analysis workflows as an assistant or as a consultant. But first, let’s discuss briefly some of the highlights of the tool, or better yet, ask Leo to present itself.

To access Leo all you need is to have the Brave browser installed in your machine and start a new conversation by typing “Ask Leo” in the search bar. Leo works more or less the same way as other popular LLMs like Chat GPT.


Using Leo AI as a Coding Assistant

As of now, despite showing astonishing capabilites, AI models are not to be fully trusted to write code. There’s still long way to cover for these computer models to work without supervision.

However, you can safely delegate tasks to them if you know what’s required to solve a problem and how to implement the solution.

In practice, since I have a thorough understanding and experience using of Python for data analysis, I feel comfortable having Leo to write the code for me, only after I figured out a detailed process.

As an example, I recently needed to update some fields in SQL database. I have done that in the past using the pymysql package so I was aware that one can execute standard queries. I could have done the same in let’s say Workbench, but since there were a few hundred fields that needed to be modified, I decided to implement the algorithm in Python to make it easier to perform array iterations (because looping in SQL is not so nice).

Here’s when Leo becomes handy. In the prompt I provide specific field names and a detailed outline of the process. Let’s look at the results.


Using Leo AI as a Coding Consultant

On the other hand, these computer models have absorved such an immense quantity of information that is plainly outside of the reach of the average human. Nonetheless, the human brain is still the most efficient machine to process and extract knowledge of complex and unrelated information.

You can leverage on the power of these models to solve tasks when you have a good understanding of how they could be done, but you are not sure about how to implement the solution.

Once again, since I’m versed in Python data structures and algorithms, when I need to implement similar workflows in another programming language, I first think about the process and then ask Leo to write a draft version of the code.

I recently wrote a post about creating a data pipeline from Airtable to Google Sheets. One of the challenges I faced to achieve that goal was to create a recursive function to extract data from an API call. The response from the API was limited to a hundred records per request, and if there was a remainder of the data, the response will include an “offset” that should be attached at the end of the URL to get the next batch.

If I was to implement such process in Python I would have leveraged on string operations and the requests / Beautiful Soup combo to handle this. But since I need to create this in App Scripts, I asked Leo to help me. The key is to be as explicit as possible to have better results. Let’s check the output.

Of course I refined this template several times before having the final version (which you can check in the original post)

In conclusion, AI tools like Brave’s Leo could certainly assist in regular data analysis tasks if we understand the challenge we have at hand and delegate the code writing to the model after we had figured out the process. The better one understand the process, the more we can rely on the AI. Nevertheless, this tools are not a subsitute for good reasoning and problem solving skills.

To view or add a comment, sign in

More articles by Iván Calderón

Insights from the community

Others also viewed

Explore topics