我正在读取一个excel文件,如下所示,使用pandas并将结果写入数据帧。

我想要获取每个测试用例的"Expected“列中的行数。我使用了len函数,它抛出了"TypeError:'numpy.int64‘类型的对象没有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发布于 2020-11-20 04:24:54
在没有看到数据帧数据的情况下,很难说这是否会起作用,因为还不清楚熊猫如何处理合并后的excel数据。
不过,一般而言:
df_counts = df.groupby('Test').count().reset_index() # won't give you the text, but a new dataframe https://stackoverflow.com/questions/64915687
复制相似问题