{"id":21448567,"url":"https://github.com/rbitr/cpa","last_synced_at":"2026-02-12T19:02:11.016Z","repository":{"id":262632360,"uuid":"887869125","full_name":"rbitr/cpa","owner":"rbitr","description":"LLM / AI data science agent, using Anthropic's Claude and PANDAS","archived":false,"fork":false,"pushed_at":"2024-11-13T12:38:57.000Z","size":71,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-05T09:41:50.762Z","etag":null,"topics":["agents","anthropic","claude","data-science","pandas"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","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/rbitr.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-13T12:29:53.000Z","updated_at":"2025-03-21T17:17:19.000Z","dependencies_parsed_at":"2024-11-13T13:41:55.419Z","dependency_job_id":"bde92e16-03d4-427f-99c1-672e4cea17cc","html_url":"https://github.com/rbitr/cpa","commit_stats":null,"previous_names":["rbitr/cpa"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rbitr/cpa","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbitr%2Fcpa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbitr%2Fcpa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbitr%2Fcpa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbitr%2Fcpa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rbitr","download_url":"https://codeload.github.com/rbitr/cpa/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbitr%2Fcpa/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29377911,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-12T18:59:55.292Z","status":"ssl_error","status_checked_at":"2026-02-12T18:59:44.289Z","response_time":55,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["agents","anthropic","claude","data-science","pandas"],"created_at":"2024-11-23T03:15:54.002Z","updated_at":"2026-02-12T19:02:11.001Z","avatar_url":"https://github.com/rbitr.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Claude Pandas Agent (CPA)\n\nThis is a demo of an \"AI\" agent using Anthropic's tool calling and the \nPANDAS python library. The agent can run arbitrary PANDAS Dataframe operations\n(based on the assumed inherent PANDAS knowledge that Claude has) on data\nstored in a stack and register. \n\nThis is experimental and limited, but does pretty well for something\nso basic.\n\nThe basic loop is to call pandas functions on a data set and then look at the \noutput to decide what to do next. Importantly, this includes generting\nfigures and analyzing them using Claude's vision functionality, so we can\nmake charts and then describe them, which is cool.\n\nAll of the \"tools\" the agent needs are defined as pydantic models in cpa.py\n\nThese are:\n\n```python\nclass DataFrameOperation(BaseModel):\n    \"\"\"Call a member function of a Pandas DataFrame in the \"stack\".\"\"\"\n\nclass SeriesOperation(BaseModel):\n    \"\"\"Call a member function of a Pandas Series in the series register.\"\"\" \n\nclass Pop(BaseModel):\n    \"\"\"Pop the top DataFrame from the stack.\"\"\"\n\nclass SeriesAssign(BaseModel):\n    \"\"\"Assign the series in the series register to the dataframe at the top of the stack.\"\"\"\n```\n\nThe LLM is prompted to make a decision of what tool to use at each step. A full\n demo, with the output in the linked [demo.ipynb](demo.ipynb) is below. Note \nthat an Anthropic API key is necessary for it to work and must be added\nto the environment with `export ANTHROPIC_API_KEY=\u003cyour key\u003e`\n\n```python\nfrom cpa import init, step\n\nrequest = \"Analyze the relationship between family size (SibSp + Parch) and survival rate, including a visualization of your findings.\"\ncsv_file = \"data/titanic.csv\"\nstate = init(request,csv_file)\n\nwhile state.tool_call:\n    step(state)\n```\n\n### Output\n```\nwhile state.tool_call:\n    step(state)\n\nTo analyze the relationship between family size and survival rate, including a visualization, we'll need to perform a few steps. Let's start by creating a new column for family size and then calculate the survival rate based on family size.\n\n1. First, let's create a new column for family size:\ndataframe_operation\n{'target_frame': 0, 'function': 'eval', 'kwargs': {'expr': 'SibSp + Parch'}}\n\n...\n[steps omitted]\n...\nNow that we have the survival rates for each family size, let's create a bar plot to visualize this relationship:\nseries_operation\n{'function': 'plot.bar', 'kwargs': {'figsize': [10, 6], 'title': 'Survival Rate by Family Size', 'xlabel': 'Family Size', 'ylabel': 'Survival Rate'}}\n```\n\n![](resources/example.png)\n\n```\nBased on the analysis of the relationship between family size and survival rate on the Titanic, we can draw the following conclusions:\n\n1. Family size distribution:\n   - The dataset includes family sizes ranging from 0 (traveling alone) to 10.\n   - Most passengers had family sizes between 0 and 3.\n\n2. Survival rates:\n   - Passengers traveling alone (family size 0) had a survival rate of about 30.4%.\n   - Passengers with a family size of 1-3 had higher survival rates:\n     * Family size 1: 55.3% survival rate\n     * Family size 2: 57.8% survival rate\n     * Family size 3: 72.4% survival rate (highest survival rate)\n   - Survival rates generally decreased for larger family sizes:\n     * Family size 4: 20.0% survival rate\n     * Family size 5: 13.6% survival rate\n   - There were some exceptions for very large family sizes, but these might be due to small sample sizes:\n     * Family size 6: 33.3% survival rate\n     * Family size 7 and 10: 0% survival rate (likely very few passengers in these categories)\n\n3. Key observations:\n   - Passengers with small to medium-sized families (1-3 members) had the highest survival rates.\n   - The optimal family size for survival appears to be 3, with a 72.4% survival rate.\n   - Traveling alone was associated with a lower survival rate compared to having a small family.\n   - Very large families (5 or more members) generally had lower survival rates, possibly due to difficulties in keeping the entire family together during the emergency or limited resources for large groups.\n\n4. Possible explanations:\n   - Small families might have been better able to stay together and help each other during the disaster.\n   - Passengers with families might have had higher priority for lifeboats, especially women and children.\n   - Very large families might have faced challenges in coordinating their evacuation or securing spots on lifeboats for all members.\n\n5. Limitations:\n   - The analysis doesn't account for other factors that might influence survival, such as passenger class, age, or gender.\n   - Some family size categories (especially larger ones) might have small sample sizes, making their survival rates less reliable.\n\nIn conclusion, there is a clear relationship between family size and survival rate on the Titanic. Passengers traveling with small families (1-3 members) had the highest chances of survival, with those in a family of three having the best odds. This information could be valuable for understanding the dynamics of survival in maritime disasters and could potentially inform emergency protocols for future passenger ships.\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frbitr%2Fcpa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frbitr%2Fcpa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frbitr%2Fcpa/lists"}