【发布时间】:2021-03-03 01:20:12
【问题描述】:
我正在使用 pandas 读取如下 excel 文件并将结果写入数据框。
我想获取每个 Testcase 的“预期结果”列中存在的行数。我使用了 len 函数,它抛出 "TypeError: object of type 'numpy.int64' has no len()" 错误。有没有办法从 excel 中为 python 中的每个测试捕获行数。
这是我的代码
df = pd.read_excel("input_test_2.xlsx")
testcases = df['Test'].values
expected_result = df['Expected Result'].values
for i in range(0,len(df)):
testcase_nm = testcases[i]
_expected = expected_result[i]
print("Count of Expected Result:" , len(_expected))
This is the Output I am looking for :
Testcase-1 , Count of Expected Result: 1
Testcase-2 , Count of Expected Result: 3
【问题讨论】:
标签: python-3.x pandas dataframe