{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f6a5fb18",
   "metadata": {},
   "source": [
    "\n",
    "# Subsetting Single-Case Experimental Design Data\n",
    "\n",
    "The `subset_scd` function allows filtering a single-case dataset based on a specified logical condition.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6744f017",
   "metadata": {},
   "source": [
    "\n",
    "## Filtering Data with `subset_scd`\n",
    "\n",
    "The `subset_scd` function filters a single-case dataset by applying a logical condition.\n",
    "\n",
    "### Required Arguments:\n",
    "- `scdf`: A Pandas DataFrame containing SCED data.\n",
    "- `condition`: A string-based condition used for filtering (e.g., `'teacher == 1'`).\n",
    "\n",
    "The function returns a DataFrame containing only the rows that match the given condition. If an invalid condition is provided, an error will be raised.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "259e326c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "📖 scia 1.100.31 - For Documentation, visit: xxx\n"
     ]
    }
   ],
   "source": [
    "\n",
    "import scia as sc\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d0bafaaf",
   "metadata": {},
   "source": [
    "\n",
    "### Example 1: Filtering Data Based on a Condition\n",
    "\n",
    "In this example, we filter the dataset to include only rows where `teacher == 1`.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4eedff4a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  case         phase  values  teacher\n",
      "0    A      Baseline       5        1\n",
      "2    B      Baseline       3        1\n",
      "3    B  Intervention       7        1\n"
     ]
    }
   ],
   "source": [
    "\n",
    "import pandas as pd\n",
    "\n",
    "# Create a sample dataset\n",
    "df = pd.DataFrame({\n",
    "    \"case\": [\"A\", \"A\", \"B\", \"B\", \"C\", \"C\"],\n",
    "    \"phase\": [\"Baseline\", \"Intervention\", \"Baseline\", \"Intervention\", \"Baseline\", \"Intervention\"],\n",
    "    \"values\": [5, 6, 3, 7, 2, 8],\n",
    "    \"teacher\": [1, 0, 1, 1, 0, 0]\n",
    "})\n",
    "\n",
    "# Apply filtering\n",
    "df_filtered = sc.subset_scd(df, \"teacher == 1\")\n",
    "print(df_filtered)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "146517b1",
   "metadata": {},
   "source": [
    "\n",
    "### Example 2: Filtering Data Using Multiple Conditions\n",
    "\n",
    "Filtering the dataset to include only rows where `teacher == 1` and `values > 4`.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5ceb7ea4",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "df_filtered = sc.subset_scd(df, \"teacher == 1 and values > 4\")\n",
    "print(df_filtered)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
