我必须使用2个已经存在的具有IF-ELSE条件的列的结果来生成新列,但是我得到一个错误提示
IndexError: list index out of range
当我使用下面提到的命令检查数据长度时-
print(len(BaseYearData)-1)
print(len(BaseYearData["BUSINESS_FULL_COUNTRY_NAME"]))
print(len(BaseYearData["SUPPLIER_FULL_COUNTRY_NAME"]))
print(BaseYearData["BUSINESS_FULL_COUNTRY_NAME"][829200])
print(BaseYearData["SUPPLIER_FULL_COUNTRY_NAME"][829200])
我的结果如下所述:
829200
829201
829201
UNITED KINGDOM
UNITED STATES
这些命令已经给出了错误
print(BaseYearData["SUPPLIER_FULL_COUNTRY_NAME"][829201])
print(BaseYearData["BUSINESS_FULL_COUNTRY_NAME"][829201])
我的代码就像beloew:
domint = pd.Series(())
def domorint():
for i in range(1, len(BaseYearData)-1):
if BaseYearData["BUSINESS_FULL_COUNTRY_NAME"][i] != ["SUPPLIER_FULL_COUNTRY_NAME"][i]:
domint[i] = "Domestic"
else:
domint[i] = "International"
domorint()
BaseYearData.insert(2, "domint", domint, allow_duplicates=True)
我想根据IF-ELSE为每一行生成domint列。