{"id":8489,"date":"2023-12-18T08:13:02","date_gmt":"2023-12-18T16:13:02","guid":{"rendered":"https:\/\/live-cometml.pantheonsite.io\/?p=8489"},"modified":"2025-04-29T12:01:47","modified_gmt":"2025-04-29T12:01:47","slug":"llms-exploring-data-with-yolopandas-and-comet","status":"publish","type":"post","link":"https:\/\/www.comet.com\/site\/blog\/llms-exploring-data-with-yolopandas-and-comet\/","title":{"rendered":"LLMs: Exploring Data with YOLOPandas \ud83d\udc3c and Comet"},"content":{"rendered":"\n<figure class=\"wp-block-image aligncenter bg ln ms c\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*t10ltaMXiiGjVXzRerApTw.jpeg\" alt=\"yolopandas, pandas\"\/><figcaption class=\"wp-element-caption\">Image source:&nbsp;<a href=\"http:\/\/Unsplash.com\">Unsplash<\/a><\/figcaption><\/figure>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv fo bj\" id=\"3109\">Have you ever imagined how cool it would be to analyze, explore and visualize your data in Pandas without typing a single line of code by yourself?<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv fo bj\" id=\"42b5\">The world is changing so fast with the advent of LLMs (large language models). During my quest for more knowledge on LLMs and how to better leverage what this new tech has in store, I came across&nbsp;<a class=\"af my\" href=\"https:\/\/pypi.org\/project\/yolopandas\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">YOLOPandas<\/a>, a tool to interact with Pandas objects via LLMs and&nbsp;<a class=\"af my\" href=\"https:\/\/github.com\/hwchase17\/langchain\" target=\"_blank\" rel=\"noopener ugc nofollow\">LangChain<\/a>.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv fo bj\" id=\"82ef\">This article will dive into YOLOPandas, flex its abilities, and incorporate it with Comet.<\/p>\n\n\n\n<h2 class=\"wp-block-heading nw nx fv be ny nz oa ob oc od oe of og oh oi oj ok ol om on oo op oq or os ot bj\" id=\"9075\">Overview of YOLOPandas<\/h2>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb ou nd ne nf ov nh ni nj ow nl nm nn ox np nq nr oy nt nu nv fo bj\" id=\"0914\">YOLOPandas is based on Langchain, a powerful library allowing abstractions over language models from different providers. It lets you specify commands with natural language and execute them directly on Pandas objects. You can preview the code before executing or set&nbsp;<code class=\"cw oz pa pb pc b\">yolo=True<\/code>&nbsp;to execute the code straight from the LLM.<\/p>\n\n\n\n<h3 class=\"wp-block-heading pd nx fv be ny pe pf pg oc ph pi pj og nj pk pl pm nn pn po pp nr pq pr ps pt bj\" id=\"d828\">Installation<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"69ca\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\">pip install yolopandas<\/span><\/pre>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv fo bj\" id=\"6d1d\">Once imported into our notebook, YOLOPandas adds an&nbsp;<code class=\"cw oz pa pb pc b\">llm<\/code>&nbsp;accessor to Pandas DataFrames. We will consider two examples of how this works and better understand how to use it for maximum productivity.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv fo bj\" id=\"036f\"><strong class=\"be qh\">Note<\/strong>: We will need an OpenAI API key, which can be found on our account&nbsp;<a class=\"af my\" href=\"https:\/\/platform.openai.com\/account\/api-keys\" target=\"_blank\" rel=\"noopener ugc nofollow\">here<\/a>, then we will need to set it as an environment variable.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"b1c9\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">import<\/span> os\nos.environ[<span class=\"hljs-string\">'OPENAI_API_KEY'<\/span>] = <span class=\"hljs-string\">'*******'<\/span><\/span><\/pre>\n\n\n\n<h2 class=\"wp-block-heading nw nx fv be ny nz oa ob oc od oe of og oh oi oj ok ol om on oo op oq or os ot bj\" id=\"202b\">First Example: Using a Dataset<\/h2>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb ou nd ne nf ov nh ni nj ow nl nm nn ox np nq nr oy nt nu nv fo bj\" id=\"341e\">We will use a movie rating dataset that I got from Kaggle. It contains data about different movies, their runtimes, IMDb ratings, where they were produced, and lots more.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong class=\"be qh\">Import the libraries.<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"015d\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">from<\/span> yolopandas <span class=\"hljs-keyword\">import<\/span> pd\n\n<span class=\"hljs-keyword\">import<\/span> matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt<\/span><\/pre>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv fo bj\" id=\"2efd\">We imported the YOLOPandas library into our notebook as well as the Matplotlib library for visualizations.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong class=\"be qh\">Explore the dataset.<\/strong><\/li>\n<\/ul>\n\n\n\n<div><\/div>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv fo bj\" id=\"8a5c\">We can now start exploring the dataset using the LLM accessor. By default, the&nbsp;<code class=\"cw oz pa pb pc b\">yolo<\/code>&nbsp;parameter is set to&nbsp;<code class=\"cw oz pa pb pc b\">false<\/code>&nbsp;which gives us the ability to preview the code before executing and either accept it and apply it or reject it. When we set&nbsp;<code class=\"cw oz pa pb pc b\">yolo=True<\/code>&nbsp;it applies the code without any preview and executes the code straight from the LLM.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv fo bj\" id=\"85ab\">The&nbsp;<code class=\"cw oz pa pb pc b\">yolo<\/code>&nbsp;parameter is a boolean flag that controls whether or not the code is executed straight from the LLM. The&nbsp;<code class=\"cw oz pa pb pc b\">yolo<\/code>&nbsp;parameter can be used with any of the YOLOPandas query functions.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"cfb8\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\">movie_reviews.llm.query(<span class=\"hljs-string\">\"Show the first three movies in the dataset\"<\/span>, yolo=<span class=\"hljs-literal\">True<\/span>)<\/span><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter pu pv pw px py mn mf mg paragraph-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*1yDbjDTU36OMvbEgebwyLA.png\" alt=\"yolopandas, pandas\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"be0f\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\">movie_reviews.llm.query(<span class=\"hljs-string\">\"for each movie, count the number of reviews and their average score. Show the 5 with the highest reviews\"<\/span>, yolo=<span class=\"hljs-literal\">True<\/span>)<\/span><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter pu pv pw px py mn mf mg paragraph-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*5rcgneaiBXIK3DeWsNSqFQ.png\" alt=\"yolopandas, pandas\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"25c0\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\">movie_reviews.llm.query(<span class=\"hljs-string\">\"Show the row with the movie title 'The Gift' in the dataset\"<\/span>, yolo=<span class=\"hljs-literal\">True<\/span>)<\/span><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter pu pv pw px py mn mf mg paragraph-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*VVdmvc_XD0Wmd6oZyr1YHw.png\" alt=\"yolopandas, pandas\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"d22e\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\">movie_reviews.llm.query(<span class=\"hljs-string\">\"make a bar chart showing the rating of the movie The Gift\"<\/span>, yolo=<span class=\"hljs-literal\">True<\/span>)<\/span><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter pu pv pw px py mn mf mg paragraph-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*wxNE_vpuCgPR1GUMpDotmQ.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"9873\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\">movie_reviews.llm.query(<span class=\"hljs-string\">\"Show 5 movies with the highest rating, their year of release and production countries\"<\/span>, yolo=<span class=\"hljs-literal\">True<\/span>)<\/span><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter pu pv pw px py mn mf mg paragraph-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*0PXTTBfcI5gdj287d0kFQg.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"e341\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\">movie_reviews.llm.query(<span class=\"hljs-string\">\"Show 5 movies with the lowest rating, their year of release and production countries\"<\/span>, yolo=<span class=\"hljs-literal\">True<\/span>)<\/span><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter pu pv pw px py mn mf mg paragraph-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*c5rbrDv65hPtHilXrp9aww.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"b74d\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\">movie_reviews.llm.query(<span class=\"hljs-string\">\"Create a line chart to show the number of movies produced in the US\"<\/span>, yolo=<span class=\"hljs-literal\">True<\/span>)<\/span><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter pu pv pw px py mn mf mg paragraph-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*uvWIqkQCad9d2nY2VKtpKg.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"35e2\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\">movie_reviews.llm.query(<span class=\"hljs-string\">\"What is the oldest movie in the dataset\"<\/span>, yolo=<span class=\"hljs-literal\">True<\/span>)<\/span><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter pu pv pw px py mn mf mg paragraph-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*VY5dZTOkAbFS4UQzvRlQtg.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"fdde\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\">movie_reviews.llm.query(<span class=\"hljs-string\">\"What movies has the highest runtime in the dataset\"<\/span>, yolo=<span class=\"hljs-literal\">True<\/span>)<\/span><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter pu pv pw px py mn mf mg paragraph-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*B6xcv-Q1wh-oWl6OxCN0wA.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv fo bj\" id=\"638e\">You can go ahead and explore and analyze the dataset, and once we are done, we will log the dataset to&nbsp;<a class=\"af my\" href=\"https:\/\/www.comet.com\/site\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">Comet<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"96df\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">from<\/span> comet_ml <span class=\"hljs-keyword\">import<\/span> Artifact, Experiment\n\n\nmovie_dataset = pd.read_csv(<span class=\"hljs-string\">\"titles.csv\"<\/span>)\n\nartifact_one = Artifact(name=<span class=\"hljs-string\">\"Training-dataset\"<\/span>, artifact_type=<span class=\"hljs-string\">\"dataset\"<\/span>)\nartifact_one.add(<span class=\"hljs-string\">\"titles.csv\"<\/span>)\n\n<span class=\"hljs-comment\">#log the two datasets as artifacts to Comet<\/span>\nexperiment.log_artifact(artifact_one)<\/span><\/pre>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv fo bj\" id=\"e9ea\">We then have to end the experiment.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"afdf\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\"><span class=\"hljs-comment\">#End experiment <\/span>\nexperiment.end()<\/span><\/pre>\n\n\n\n<h2 class=\"wp-block-heading nw nx fv be ny nz oa ob oc od oe of og oh oi oj ok ol om on oo op oq or os ot bj\" id=\"1547\">Second Example: Using a Pandas DataFrame<\/h2>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb ou nd ne nf ov nh ni nj ow nl nm nn ox np nq nr oy nt nu nv fo bj\" id=\"b3c3\">We were able to explore a dataset in the first example. Similarly, we can do the same to a Pandas DataFrame. The first thing to do is create the DataFrame, and without YOLOPandas imported into the notebook, we can start using the LLM accessor to write the queries.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv fo bj\" id=\"e0b1\"><strong class=\"be qh\">Create the DataFrame.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"5f83\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\">product_df = pd.DataFrame(\n    [\n        {<span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"The Da Vinci Code\"<\/span>, <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-string\">\"book\"<\/span>, <span class=\"hljs-string\">\"price\"<\/span>: <span class=\"hljs-number\">15<\/span>, <span class=\"hljs-string\">\"quantity\"<\/span>: <span class=\"hljs-number\">300<\/span>, <span class=\"hljs-string\">\"rating\"<\/span>: <span class=\"hljs-number\">4<\/span>},\n        {<span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"Jurassic Park\"<\/span>, <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-string\">\"book\"<\/span>, <span class=\"hljs-string\">\"price\"<\/span>: <span class=\"hljs-number\">12<\/span>, <span class=\"hljs-string\">\"quantity\"<\/span>: <span class=\"hljs-number\">400<\/span>, <span class=\"hljs-string\">\"rating\"<\/span>: <span class=\"hljs-number\">4.5<\/span>},\n        {<span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"Jurassic Park\"<\/span>, <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-string\">\"film\"<\/span>, <span class=\"hljs-string\">\"price\"<\/span>: <span class=\"hljs-number\">8<\/span>, <span class=\"hljs-string\">\"quantity\"<\/span>: <span class=\"hljs-number\">6<\/span>, <span class=\"hljs-string\">\"rating\"<\/span>: <span class=\"hljs-number\">5<\/span>},\n        {<span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"Matilda\"<\/span>, <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-string\">\"book\"<\/span>, <span class=\"hljs-string\">\"price\"<\/span>: <span class=\"hljs-number\">5<\/span>, <span class=\"hljs-string\">\"quantity\"<\/span>: <span class=\"hljs-number\">80<\/span>, <span class=\"hljs-string\">\"rating\"<\/span>: <span class=\"hljs-number\">4<\/span>},\n        {<span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"Clockwork Orange\"<\/span>, <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-literal\">None<\/span>, <span class=\"hljs-string\">\"price\"<\/span>: <span class=\"hljs-literal\">None<\/span>, <span class=\"hljs-string\">\"quantity\"<\/span>: <span class=\"hljs-number\">20<\/span>, <span class=\"hljs-string\">\"rating\"<\/span>: <span class=\"hljs-number\">4<\/span>},\n        {<span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"Walden\"<\/span>, <span class=\"hljs-string\">\"type\"<\/span>: <span class=\"hljs-literal\">None<\/span>, <span class=\"hljs-string\">\"price\"<\/span>: <span class=\"hljs-literal\">None<\/span>, <span class=\"hljs-string\">\"quantity\"<\/span>: <span class=\"hljs-number\">100<\/span>, <span class=\"hljs-string\">\"rating\"<\/span>: <span class=\"hljs-number\">4.5<\/span>},\n    ],\n)\n\nproduct_df<\/span><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter pu pv pw px py mn mf mg paragraph-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*45ODNqVydwCoTfzjFz94jQ.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"5233\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\">product_df.llm.query(<span class=\"hljs-string\">\"What columns are missing values?\"<\/span>)<\/span><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter pu pv pw px py mn mf mg paragraph-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*c7V7YpDNlJD8J6ix8zbNwA.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"633c\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\">product_df.llm.query(<span class=\"hljs-string\">\"Now show me all products that are books.\"<\/span>)<\/span><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter pu pv pw px py mn mf mg paragraph-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*cCwp8oaMqgvD-Lot60M3Lw.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"4bbc\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\">product_df.llm.query(<span class=\"hljs-string\">\"Of these, which has the lowest items stocked?\"<\/span>)<\/span><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter pu pv pw px py mn mf mg paragraph-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*2TA16hnsfGjnXhWBHJa2Fg.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"2109\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-title.class\">IPython<\/span>.<span class=\"hljs-property\">display<\/span> <span class=\"hljs-keyword\">import<\/span> display\n\n\ndf1, df2 = product_df.<span class=\"hljs-property\">llm<\/span>.<span class=\"hljs-title.function\">query<\/span>(<span class=\"hljs-string\">\"Split the dataframe into two, 1\/3 in one, 2\/3 in the other. Return (df1, df2).\"<\/span>)\n\n<span class=\"hljs-title.function\">display<\/span>(df1)\n<span class=\"hljs-title.function\">display<\/span>(df2)<\/span><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter pu pv pw px py mn mf mg paragraph-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*n25-vK-cu7njEfSSZEtidQ.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv fo bj\" id=\"def9\"><strong class=\"be qh\">Visualize the DataFrame.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"a8dd\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\">product_df.llm.query(<span class=\"hljs-string\">\"Group by type and take the mean of all numeric columns.\"<\/span>, yolo=<span class=\"hljs-literal\">True<\/span>).llm.query(<span class=\"hljs-string\">\"Make a bar plot of the result and use a log scale.\"<\/span>, yolo=<span class=\"hljs-literal\">True<\/span>)<\/span><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter pu pv pw px py mn mf mg paragraph-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*rwf9ICFr4Uvu1HVpIWb2wA.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv fo bj\" id=\"14ec\">The default chain used by YOLOPandas utilizes the LangChain concept of&nbsp;<a class=\"af my\" href=\"https:\/\/langchain.readthedocs.io\/en\/latest\/modules\/memory.html\" target=\"_blank\" rel=\"noopener ugc nofollow\">memory<\/a>. This allows for \u201c<strong class=\"be qh\">remembering<\/strong>\u201d previous commands, making it possible to ask follow-up questions or ask for the execution of commands that stem from previous interactions.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv fo bj\" id=\"8b2a\">For example, the query&nbsp;<code class=\"cw oz pa pb pc b\">\"Make a Seaborn plot of price grouped by type\"<\/code>&nbsp;can be followed with&nbsp;<code class=\"cw oz pa pb pc b\">\"Can you use a dark theme, and pastel colors?\"<\/code>&nbsp;upon viewing the initial result. But if you are resetting the chain, you can also specify whether to use memory there:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"f05f\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\">df.reset_chain<span class=\"hljs-punctuation\">(<\/span>use_memory<span class=\"hljs-punctuation\">=<\/span><span class=\"hljs-literal\">False<\/span><span class=\"hljs-punctuation\">)<\/span><\/span><\/pre>\n\n\n\n<h2 class=\"wp-block-heading nw nx fv be ny nz oa ob oc od oe of og oh oi oj ok ol om on oo op oq or os ot bj\" id=\"b166\">Conclusion<\/h2>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb ou nd ne nf ov nh ni nj ow nl nm nn ox np nq nr oy nt nu nv fo bj\" id=\"2c12\">YOLOPandas queries have proven to be correct 70% \u2014 80% of the time for complex questions; even with a wrong query, the library returns the query code, making it easy to fix.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv fo bj\" id=\"3c3b\">All these queries cost money, so if you want to have a better idea of how much each query costs, you can use the function&nbsp;<code class=\"cw oz pa pb pc b\">run_query_with_cost<\/code>&nbsp;to compute the cost in $USD.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"85c9\" class=\"qc nx fv pc b bf qd qe l qf qg\" data-selectable-paragraph=\"\">\n<span class=\"hljs-keyword\">from<\/span> yolopandas.utils.query_helpers <span class=\"hljs-keyword\">import<\/span> run_query_with_cost\n\nrun_query_with_cost(product_df, <span class=\"hljs-string\">\"What item is the least expensive?\"<\/span>, yolo=<span class=\"hljs-literal\">True<\/span>)<\/span><\/pre>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv fo bj\" id=\"a09a\">You can check out your usage on OpenAI&nbsp;<a class=\"af my\" href=\"https:\/\/platform.openai.com\/account\/usage\" target=\"_blank\" rel=\"noopener ugc nofollow\">here<\/a>.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph mz na fv be b nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv fo bj\" id=\"3fe7\"><strong class=\"be qh\">\u26a0\ufe0f Warning: YOLOPandas will execute arbitrary Python code on the machine it runs on.<\/strong><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever imagined how cool it would be to analyze, explore and visualize your data in Pandas without typing a single line of code by yourself? The world is changing so fast with the advent of LLMs (large language models). During my quest for more knowledge on LLMs and how to better leverage what [&hellip;]<\/p>\n","protected":false},"author":22,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"customer_name":"","customer_description":"","customer_industry":"","customer_technologies":"","customer_logo":"","footnotes":""},"categories":[65,7],"tags":[71,52,31,16,53,32,34],"coauthors":[143],"class_list":["post-8489","post","type-post","status-publish","format-standard","hentry","category-llmops","category-tutorials","tag-language-models","tag-llm","tag-llmops","tag-ml-experiment-management","tag-mlops","tag-nlp","tag-prompt-engineering"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>LLMs: Exploring Data with YOLOPandas \ud83d\udc3c and Comet - Comet<\/title>\n<meta name=\"description\" content=\"With \ud83d\udc3c YOLOPandas, you can use natural language to interact with data and perform tasks directly on Pandas objects\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.comet.com\/site\/blog\/llms-exploring-data-with-yolopandas-and-comet\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"LLMs: Exploring Data with YOLOPandas \ud83d\udc3c and Comet\" \/>\n<meta property=\"og:description\" content=\"With \ud83d\udc3c YOLOPandas, you can use natural language to interact with data and perform tasks directly on Pandas objects\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.comet.com\/site\/blog\/llms-exploring-data-with-yolopandas-and-comet\/\" \/>\n<meta property=\"og:site_name\" content=\"Comet\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/cometdotml\" \/>\n<meta property=\"article:published_time\" content=\"2023-12-18T16:13:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-29T12:01:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*t10ltaMXiiGjVXzRerApTw.jpeg\" \/>\n<meta name=\"author\" content=\"Shittu Olumide Ayodeji\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@anmorgan2414\" \/>\n<meta name=\"twitter:site\" content=\"@Cometml\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shittu Olumide Ayodeji\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"LLMs: Exploring Data with YOLOPandas \ud83d\udc3c and Comet - Comet","description":"With \ud83d\udc3c YOLOPandas, you can use natural language to interact with data and perform tasks directly on Pandas objects","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.comet.com\/site\/blog\/llms-exploring-data-with-yolopandas-and-comet\/","og_locale":"en_US","og_type":"article","og_title":"LLMs: Exploring Data with YOLOPandas \ud83d\udc3c and Comet","og_description":"With \ud83d\udc3c YOLOPandas, you can use natural language to interact with data and perform tasks directly on Pandas objects","og_url":"https:\/\/www.comet.com\/site\/blog\/llms-exploring-data-with-yolopandas-and-comet\/","og_site_name":"Comet","article_publisher":"https:\/\/www.facebook.com\/cometdotml","article_published_time":"2023-12-18T16:13:02+00:00","article_modified_time":"2025-04-29T12:01:47+00:00","og_image":[{"url":"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*t10ltaMXiiGjVXzRerApTw.jpeg","type":"","width":"","height":""}],"author":"Shittu Olumide Ayodeji","twitter_card":"summary_large_image","twitter_creator":"@anmorgan2414","twitter_site":"@Cometml","twitter_misc":{"Written by":"Shittu Olumide Ayodeji","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.comet.com\/site\/blog\/llms-exploring-data-with-yolopandas-and-comet\/#article","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/blog\/llms-exploring-data-with-yolopandas-and-comet\/"},"author":{"name":"Abby Morgan","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/826ee39a2e30cf9d8d73155de09bb7b2"},"headline":"LLMs: Exploring Data with YOLOPandas \ud83d\udc3c and Comet","datePublished":"2023-12-18T16:13:02+00:00","dateModified":"2025-04-29T12:01:47+00:00","mainEntityOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/llms-exploring-data-with-yolopandas-and-comet\/"},"wordCount":619,"publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/llms-exploring-data-with-yolopandas-and-comet\/#primaryimage"},"thumbnailUrl":"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*t10ltaMXiiGjVXzRerApTw.jpeg","keywords":["Language Models","LLM","LLMOps","ML Experiment Management","MLOps","NLP","Prompt Engineering"],"articleSection":["LLMOps","Tutorials"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.comet.com\/site\/blog\/llms-exploring-data-with-yolopandas-and-comet\/","url":"https:\/\/www.comet.com\/site\/blog\/llms-exploring-data-with-yolopandas-and-comet\/","name":"LLMs: Exploring Data with YOLOPandas \ud83d\udc3c and Comet - Comet","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/llms-exploring-data-with-yolopandas-and-comet\/#primaryimage"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/llms-exploring-data-with-yolopandas-and-comet\/#primaryimage"},"thumbnailUrl":"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*t10ltaMXiiGjVXzRerApTw.jpeg","datePublished":"2023-12-18T16:13:02+00:00","dateModified":"2025-04-29T12:01:47+00:00","description":"With \ud83d\udc3c YOLOPandas, you can use natural language to interact with data and perform tasks directly on Pandas objects","breadcrumb":{"@id":"https:\/\/www.comet.com\/site\/blog\/llms-exploring-data-with-yolopandas-and-comet\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.comet.com\/site\/blog\/llms-exploring-data-with-yolopandas-and-comet\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/blog\/llms-exploring-data-with-yolopandas-and-comet\/#primaryimage","url":"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*t10ltaMXiiGjVXzRerApTw.jpeg","contentUrl":"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*t10ltaMXiiGjVXzRerApTw.jpeg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.comet.com\/site\/blog\/llms-exploring-data-with-yolopandas-and-comet\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.comet.com\/site\/"},{"@type":"ListItem","position":2,"name":"LLMs: Exploring Data with YOLOPandas \ud83d\udc3c and Comet"}]},{"@type":"WebSite","@id":"https:\/\/www.comet.com\/site\/#website","url":"https:\/\/www.comet.com\/site\/","name":"Comet","description":"Build Better Models Faster","publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.comet.com\/site\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.comet.com\/site\/#organization","name":"Comet ML, Inc.","alternateName":"Comet","url":"https:\/\/www.comet.com\/site\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/#\/schema\/logo\/image\/","url":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2025\/01\/logo_comet_square.png","contentUrl":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2025\/01\/logo_comet_square.png","width":310,"height":310,"caption":"Comet ML, Inc."},"image":{"@id":"https:\/\/www.comet.com\/site\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/cometdotml","https:\/\/x.com\/Cometml","https:\/\/www.youtube.com\/channel\/UCmN63HKvfXSCS-UwVwmK8Hw"]},{"@type":"Person","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/826ee39a2e30cf9d8d73155de09bb7b2","name":"Abby Morgan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/image\/dbbf1ae921ee179c768f508340415946","url":"https:\/\/secure.gravatar.com\/avatar\/28d4934d14261b4afe12e226f0eaa57c4fb0c2761ad4586eb9a5bec3b8160bc9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/28d4934d14261b4afe12e226f0eaa57c4fb0c2761ad4586eb9a5bec3b8160bc9?s=96&d=mm&r=g","caption":"Abby Morgan"},"description":"AI\/ML Growth Engineer @ Comet","sameAs":["https:\/\/www.comet.com\/","https:\/\/www.linkedin.com\/in\/anmorgan24\/","https:\/\/x.com\/anmorgan2414"],"url":"https:\/\/www.comet.com\/site\/blog\/author\/abigailmcomet-com\/"}]}},"_links":{"self":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/8489","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/comments?post=8489"}],"version-history":[{"count":2,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/8489\/revisions"}],"predecessor-version":[{"id":15769,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/8489\/revisions\/15769"}],"wp:attachment":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/media?parent=8489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/categories?post=8489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/tags?post=8489"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/coauthors?post=8489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}