{
  "id": "python/pandas-truth-value-ambiguous",
  "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 Series in a boolean context (if/and/or) where a scalar is expected.",
  "root_cause_type": "generic",
  "root_cause_zh": "在需要标量的布尔上下文（if/and/or）中使用了 Series。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Raises the same error for multi-element Series",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Triggers the same ambiguity error",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Use element-wise operators: (s > 0) & (s < 10); for any: s.any()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "np.where(cond, a, b) for vectorized selection",
      "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-02-08",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}