Subsetting Single-Case Experimental Design Data — SCIA - Single Case Intervention Analysis with Python

Skip to main content
`Ctrl`+`K`

# Subsetting Single-Case Experimental Design Data

The `subset_scd` function allows filtering a single-case dataset based on a specified logical condition.

## Filtering Data with `subset_scd`

The `subset_scd` function filters a single-case dataset by applying a logical condition.

### Required Arguments:

- `scdf`: A Pandas DataFrame containing SCED data.

- `condition`: A string-based condition used for filtering (e.g., `'teacher == 1'`).

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.

    import scia as sc

    📖 scia 1.101.0.dev6 - For Documentation, visit: https://ahsankhodami.github.io/scia/intro.html

### Example 1: Filtering Data Based on a Condition

In this example, we filter the dataset to include only rows where `teacher == 1`.

    import pandas as pd

    # Create a sample dataset
    df = pd.DataFrame({
        "case": ["A", "A", "B", "B", "C", "C"],
        "phase": ["Baseline", "Intervention", "Baseline", "Intervention", "Baseline", "Intervention"],
        "values": [5, 6, 3, 7, 2, 8],
        "teacher": [1, 0, 1, 1, 0, 0]
    })

    # Apply filtering
    df_filtered = sc.subset_scd(df, "teacher == 1")
    print(df_filtered)

      case         phase  values  teacher
    0    A      Baseline       5        1
    2    B      Baseline       3        1
    3    B  Intervention       7        1

### Example 2: Filtering Data Using Multiple Conditions

Filtering the dataset to include only rows where `teacher == 1` and `values > 4`.

    df_filtered = sc.subset_scd(df, "teacher == 1 and values > 4")
    print(df_filtered)

      case         phase  values  teacher
    0    A      Baseline       5        1
    3    B  Intervention       7        1