{"record":{"id":"87549a5bd4a75f18","repo":"OpenBB-finance/OpenBB","slug":"column-target-col-not-found-in-the-data","errorCode":null,"errorMessage":"Column '{target_col}' not found in the data.","messagePattern":"Column '(.+?)' not found in the data\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"openbb_platform/extensions/economy/openbb_economy/economy_views.py","lineNumber":384,"sourceCode":"            else kwargs.get(\"obbject_item\")\n        )\n        df = DataFrame()\n\n        if isinstance(_data, DataFrame) and not _data.empty:\n            df = _data.reset_index() if _data.index.name == \"date\" else _data\n        else:\n            try:\n                df = basemodel_to_df(_data, index=None)  # type: ignore\n            except Exception as e:\n                raise RuntimeError(\"Unable to process supplied data.\") from e\n\n        if df.empty or len(df) < 2:\n            raise RuntimeError(\"No data found to plot.\")\n\n        cols = df.columns.to_list()\n        target_col = kwargs.get(\"target_col\", \"value\")\n        if target_col not in cols:\n            raise RuntimeError(f\"Column '{target_col}' not found in the data.\")\n\n        new_df = df.pivot(columns=\"symbol\", values=target_col, index=\"date\")\n        target_symbols = kwargs.get(\"target_symbol\", \"\").split(\",\")[:10]  # type: ignore\n\n        if not target_symbols or len(target_symbols) == 0 or target_symbols[0] == \"\":\n            target_symbols = new_df.columns.to_list()[:10]\n\n        metadata = kwargs[\"extra\"].get(\"results_metadata\", {})  # type: ignore\n        ytitle = kwargs.get(\"ytitle\", \"\")\n\n        new_df = new_df.filter(target_symbols, axis=1)\n\n        if \"percent\" in target_col.lower():  # type: ignore\n            ytitle = (\n                ytitle\n                if ytitle\n                else target_col.replace(\"change_percent_\", \"\").replace(\"M\", \" Month\") + \" Change (%)\"  # type: ignore\n            )","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/extensions/economy/openbb_economy/economy_views.py#L366-L402","documentation":"The BLS charting view pivots the data by (symbol, date) around a value column (default 'value', overridable via target_col). If target_col is not among the DataFrame columns, the pivot is impossible and RuntimeError('Column {target_col} not found in the data.') is raised. BLS models expose the observation as 'value', so a custom payload lacking it fails here.","triggerScenarios":"Passing target_col='price' (or anything != a real column) in charting kwargs; injecting a DataFrame whose value field is named differently (e.g. 'rate', 'close'); using a provider model without a 'value' field.","commonSituations":"Reusing charting kwargs from another endpoint, custom DataFrames built from CSVs with different column names, or renaming columns during preprocessing.","solutions":["Omit target_col so the default 'value' is used with native BLS results.","Rename your injected column: df = df.rename(columns={'rate': 'value'}) before passing data=df.","Pass target_col matching an existing column: check df.columns first."],"exampleFix":"# before\nfig = views.bls_chart(data=df.rename(columns={'value':'obs'}), target_col='value')\n\n# after\ndf = df.rename(columns={'obs': 'value'})\nfig = views.bls_chart(data=df)  # default target_col='value' now resolves","handlingStrategy":"validation","validationCode":"df = res.to_df() if hasattr(res, 'to_df') else data\ntarget_col = kwargs.get('target_col', 'value')\nassert target_col in df.columns, (\n    f'{target_col!r} missing; available: {df.columns.tolist()}'\n)","typeGuard":"def has_column(df, name: str) -> bool:\n    \"\"\"True when the DataFrame exposes the named column.\"\"\"\n    return name in getattr(df, 'columns', [])","tryCatchPattern":"try:\n    fig = views.bls_chart(target_col=target_col, **kwargs)\nexcept RuntimeError as e:\n    if 'not found in the data' in str(e):\n        fig = views.bls_chart(**{k: v for k, v in kwargs.items() if k != 'target_col'})\n    else:\n        raise","preventionTips":["Omit target_col for native BLS results (defaults to 'value').","Rename injected value columns to 'value' at ingest.","Print df.columns once when wiring custom data into charting views."],"tags":["charting","bls","column-missing","pivot"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}