{"id":13577394,"url":"https://github.com/ccurme/yolopandas","last_synced_at":"2025-04-06T10:14:41.588Z","repository":{"id":65562152,"uuid":"588193088","full_name":"ccurme/yolopandas","owner":"ccurme","description":null,"archived":false,"fork":false,"pushed_at":"2023-05-11T13:08:53.000Z","size":414,"stargazers_count":197,"open_issues_count":3,"forks_count":15,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-30T09:08:36.464Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ccurme.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-01-12T14:47:23.000Z","updated_at":"2025-01-13T23:39:31.000Z","dependencies_parsed_at":"2024-01-14T09:26:15.449Z","dependency_job_id":"b45cea04-dd9d-493f-9283-3d4843f6c456","html_url":"https://github.com/ccurme/yolopandas","commit_stats":{"total_commits":72,"total_committers":4,"mean_commits":18.0,"dds":"0.13888888888888884","last_synced_commit":"db2d6b3fa50f5a2f3382a08d69a1dbde6d820b58"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccurme%2Fyolopandas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccurme%2Fyolopandas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccurme%2Fyolopandas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccurme%2Fyolopandas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ccurme","download_url":"https://codeload.github.com/ccurme/yolopandas/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247464226,"owners_count":20942970,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T15:01:21.071Z","updated_at":"2025-04-06T10:14:41.565Z","avatar_url":"https://github.com/ccurme.png","language":"Python","funding_links":[],"categories":["Python","Chatbots"],"sub_categories":[],"readme":"# YOLOPandas\n\nInteract with Pandas objects via LLMs and [LangChain](https://github.com/hwchase17/langchain).\n\nYOLOPandas lets you specify commands with natural language and execute them directly on Pandas objects.\nYou can preview the code before executing, or set `yolo=True` to execute the code straight from the LLM.\n\n**Warning**: YOLOPandas will execute arbitrary Python code on the machine it runs on. This is a dangerous thing to do.\n\nhttps://user-images.githubusercontent.com/26529506/214591990-c295a283-b9e6-4775-81e4-28917183ebb1.mp4\n\n## Quick Install\n\n`pip install yolopandas`\n\n## Basic usage\n\nYOLOPandas adds a `llm` accessor to Pandas dataframes.\n\n```python\nfrom yolopandas import pd\n\ndf = pd.DataFrame(\n    [\n        {\"name\": \"The Da Vinci Code\", \"type\": \"book\", \"price\": 15, \"quantity\": 300, \"rating\": 4},\n        {\"name\": \"Jurassic Park\", \"type\": \"book\", \"price\": 12, \"quantity\": 400, \"rating\": 4.5},\n        {\"name\": \"Jurassic Park\", \"type\": \"film\", \"price\": 8, \"quantity\": 6, \"rating\": 5},\n        {\"name\": \"Matilda\", \"type\": \"book\", \"price\": 5, \"quantity\": 80, \"rating\": 4},\n        {\"name\": \"Clockwork Orange\", \"type\": None, \"price\": None, \"quantity\": 20, \"rating\": 4},\n        {\"name\": \"Walden\", \"type\": None, \"price\": None, \"quantity\": 100, \"rating\": 4.5},\n    ],\n)\n\ndf.llm.query(\"What item is the least expensive?\")\n```\nThe above will generate Pandas code to answer the question, and prompt the user to accept or reject the proposed code.\nAccepting it in this case will return a Pandas dataframe containing the result.\n\nAlternatively, you can execute the LLM output without first previewing it:\n```python\ndf.llm.query(\"What item is the least expensive?\", yolo=True)\n```\n\n`.query` can return the result of the computation, which we do not constrain. For instance, while `\"Show me products under $10\"` will return a dataframe, the query `\"Split the dataframe into two, 1/3 in one, 2/3 in the other. Return (df1, df2)\"` can return a tuple of two dataframes. You can also chain queries together, for instance:\n```python\ndf.llm.query(\"Group by type and take the mean of all numeric columns.\", yolo=True).llm.query(\"Make a bar plot of the result and use a log scale.\", yolo=True)\n```\n\nAlso, if you want to get a better idea of how much each query costs, you can use the function `run_query_with_cost` found in the utils module to compute the cost in $USD broken down by prompt/completion tokens:\n\n```python\n\nfrom yolopandas.utils.query_helpers import run_query_with_cost\n\nrun_query_with_cost(df, \"What item is the least expensive?\", yolo=True)\n```\nAfter running the above code, the output looks like the following:\n\n```\nTotal Tokens: 267\nPrompt Tokens: 252\nCompletion Tokens: 15\nTotal Cost (USD): $0.00534\n```\n\n\nSee the [example notebook](docs/example_notebooks/example.ipynb) for more ideas.\n\n\n## LangChain Components\n\nThis package uses several LangChain components, making it easy to work with if you are familiar with LangChain. In particular, it utilizes the LLM, Chain, and Memory abstractions.\n\n### LLM Abstraction\n\nBy working with LangChain's LLM abstraction, it is very easy to plug-and-play different LLM providers into YOLOPandas. You can do this in a few different ways:\n\n1. You can change the default LLM by specifying a config path using the `LLPANDAS_LLM_CONFIGURATION` environment variable. The file at this path should be in [one of the accepted formats](https://langchain.readthedocs.io/en/latest/modules/llms/examples/llm_serialization.html).\n\n2. If you have a LangChain LLM wrapper in memory, you can set it as the default LLM to use by doing:\n\n```python\nimport yolopandas\nyolopandas.set_llm(llm)\n```\n\n3. You can set the LLM wrapper to use for a specific dataframe by doing: `df.reset_chain(llm=llm)`\n\n\n### Chain Abstraction\n\nBy working with LangChain's Chain abstraction, it is very easy to plug-and-play different chains into YOLOPandas. This can be useful if you want to customize the prompt, customize the chain, or anything like that.\n\nTo use a custom chain for a particular dataframe, you can do:\n\n```python\ndf.set_chain(chain)\n```\n\nIf you ever want to reset the chain to the base chain, you can do:\n\n```python\ndf.reset_chain()\n```\n\n### Memory Abstraction\n\nThe default chain used by YOLOPandas utilizes the LangChain concept of [memory](https://langchain.readthedocs.io/en/latest/modules/memory.html). This allows for \"remembering\" of previous commands, making it possible to ask follow up questions or ask for execution of commands that stem from previous interactions.\n\nFor example, the query `\"Make a seaborn plot of price grouped by type\"` can be followed with `\"Can you use a dark theme, and pastel colors?\"` upon viewing the initial result.\n\nBy default, memory is turned on. In order to have it turned off by default, you can set the environment variable `LLPANDAS_USE_MEMORY=False`.\n\nIf you are resetting the chain, you can also specify whether to use memory there:\n\n```python\ndf.reset_chain(use_memory=False)\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccurme%2Fyolopandas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fccurme%2Fyolopandas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccurme%2Fyolopandas/lists"}