我有一个像这样的pd.dataframe:
0 1
0 10 0.9679487179487178
1 38 0.9692307692307693
2 24 0.9833333333333332
3 62 0.9525641025641025
4 17 0.9679487179487178
5 23 0.9679487179487178
6 72 0.9679487179487178
7 22 0.9538461538461538
8 90 0.9525641025641025
9 32 0.9666666666666668我如何让蟒蛇打印出这样的信息:“最高精度为0.9833333333333332,使用24个特征;第二高精度为0.9692307692307693,38个特征;第三,最高精度为0.9679487179487178,10个特征。”
发布于 2022-06-21 12:06:55
如果您按照这种准确性对数据进行排序,如下所示:
df.sort_values(by=["1"], inplace=True)你想要你能做到的三个最高的精确性:
for i in range(3):
print(f"Top {i+1} accuracy was {df["1"].loc[i]} with {df["0"].loc[i]} features")如果您想准确地打印您在这个问题上所写的内容,那么只需将{i+1}替换为{order[i]}并创建order = ["Highest", "Second Highest", "Third Highest"]即可。
发布于 2022-06-21 12:25:06
您可以使用pandas.DataFrame.nlargest
out = df.nlargest(3, '1')print(out)
0 1
2 24 0.983333
1 38 0.969231
0 10 0.967949发布于 2022-06-21 12:08:48
使用acc列对文件进行排序,如下所示:
data.sort_values("column name", axis=0, ascending=True, inplace=True, na_position='first')然后按顺序打印你想要的
https://stackoverflow.com/questions/72700400
复制相似问题