In Python, I'm trying to create code that iterates and checks if Gender is "E", and if yes, then if "IncState" is "ca", "california" (regardless of capitalization) or None
, then it inserts "California", else it inserts the value in DefendantsTbl['IncState'][i].
I keep getting a "ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()." error.
This is sample data.
Name | Gender | ShortName | Business | State | ZipCode | IncState | MergeName | |
---|---|---|---|---|---|---|---|---|
0 | Company1 | E | CWI | None | None | None | None | CWI |
1 | Company2 | E | None | None | None | None | Delaware | Company2 |
This is the code I am using.
import os, sys
import pandas as pd
from janitor import xlsx_table
from docx.shared import Inches, Pt
import numpy as np
import xlwings as xw
from docx import Document
from docx.enum.style import WD_STYLE_TYPE
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from time import perf_counter
doc = Document()
docap = doc.add_paragraph
for i in range(len(DefendantsTbl)):
if DefendantsTbl['Gender'][i].lower() == 'e':
docap('At all times material hereto, ' + DefendantsTbl['Name'][i] + ' was a '
+ ('California' if (str(DefendantsTbl['IncState'][i]).lower() == 'california')
or (str(DefendantsTbl['IncState'][i]).lower() ==
'ca') or (DefendantsTbl['IncState'][i] is None)
else DefendantsTbl['IncState'][i]) + 'corporation that regularly transacted business in ' + CaseInfoTbl['County'] + ' County, California.')