{
  "id": "python/pandas-ambiguous-truth-value",
  "signature": "ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().",
  "signature_zh": "ValueError: Series 的真值不明确。请使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()。",
  "regex": "ValueError:\\ The\\ truth\\ value\\ of\\ a\\ Series\\ is\\ ambiguous\\.\\ Use\\ a\\.empty,\\ a\\.bool\\(\\),\\ a\\.item\\(\\),\\ a\\.any\\(\\)\\ or\\ a\\.all\\(\\)\\.",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Using a pandas Series inside an if/and/or expression. Series has no single boolean truth value, so Python's conditional evaluation fails.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 if/and/or 表达式中使用 pandas Series。Series 没有单一布尔真值，导致 Python 条件求值失败。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Still ambiguous for multi-element arrays",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Same ValueError raised",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Use elementwise ops: df.loc[df['a'] > 0, 'b'] = 1",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Reduce first: if (df['a'] > 0).any(): ...",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-08",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}