{"record":{"id":"a75cdd9474587896","repo":"run-llama/llama_index","slug":"pandas-is-required-for-this-function-please-insta","errorCode":null,"errorMessage":"pandas is required for this function. Please install it with `pip install pandas`.","messagePattern":"pandas is required for this function\\. Please install it with `pip install pandas`\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/evaluation/notebook_utils.py","lineNumber":21,"sourceCode":"from collections import defaultdict\nfrom typing import Any, List, Optional, Tuple\n\nfrom llama_index.core.evaluation import EvaluationResult\nfrom llama_index.core.evaluation.retrieval.base import RetrievalEvalResult\n\nDEFAULT_METRIC_KEYS = [\"hit_rate\", \"mrr\"]\n\n\ndef get_retrieval_results_df(\n    names: List[str],\n    results_arr: List[List[RetrievalEvalResult]],\n    metric_keys: Optional[List[str]] = None,\n) -> Any:\n    \"\"\"Display retrieval results.\"\"\"\n    try:\n        import pandas as pd\n    except ImportError:\n        raise ImportError(\n            \"pandas is required for this function. Please install it with `pip install pandas`.\"\n        )\n\n    metric_keys = metric_keys or DEFAULT_METRIC_KEYS\n\n    avg_metrics_dict = defaultdict(list)\n    for name, eval_results in zip(names, results_arr):\n        metric_dicts = []\n        for eval_result in eval_results:\n            metric_dict = eval_result.metric_vals_dict\n            metric_dicts.append(metric_dict)\n        results_df = pd.DataFrame(metric_dicts)\n\n        for metric_key in metric_keys:\n            if metric_key not in results_df.columns:\n                raise ValueError(f\"Metric key {metric_key} not in results_df\")\n            avg_metrics_dict[metric_key].append(results_df[metric_key].mean())\n","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/evaluation/notebook_utils.py#L3-L39","documentation":"get_retrieval_results_df needs pandas to build summary DataFrames of retrieval metrics (hit_rate, mrr, ...). pandas is an optional dependency of llama-index-core, so the function imports it lazily and raises ImportError with install instructions when it is absent.","triggerScenarios":"Calling get_retrieval_results_df(names, results_arr) in an environment where `import pandas` fails (pandas not installed).","commonSituations":"Minimal llama-index installs (llama-index-core only) in notebooks or CI; slim Docker images; copying notebook eval helpers into a service that never installed pandas.","solutions":["pip install pandas","Or add pandas to your project's dependencies/requirements so eval environments always have it","If you can't install pandas, compute averages manually from RetrievalEvalResult.metric_vals_dict instead of this helper"],"exampleFix":"# before\nfrom llama_index.core.evaluation.notebook_utils import get_retrieval_results_df\ndf = get_retrieval_results_df(names, results)  # ImportError\n\n# after\n# pip install pandas\ndf = get_retrieval_results_df(names, results)","handlingStrategy":"validation","validationCode":"def pandas_available() -> bool:\n    try:\n        import pandas  # noqa: F401\n        return True\n    except ImportError:\n        return False\n\nif pandas_available():\n    df = get_retrieval_results_df(names, results)\nelse:\n    df = None  # aggregate manually from result.metric_vals_dict","typeGuard":null,"tryCatchPattern":"try:\n    df = get_retrieval_results_df(names, results)\nexcept ImportError as e:\n    if \"pandas\" in str(e):\n        logger.error(\"pip install pandas to use notebook eval helpers\")\n    raise","preventionTips":["Include pandas in any environment running eval notebooks/helpers","Declare pandas as a project dependency when eval tooling is part of the repo","Fallback path: average metric_vals_dict values manually without pandas"],"tags":["import-error","dependency","pandas","evaluation","notebook"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}