以下是一个使用Python进行排序并找到最大值的示例代码,不使用pandas:
# 用于按照特定列排序的函数
def sort_by_column(arr, column):
arr.sort(key=lambda x: x[column], reverse=True)
return arr
# 样例数据
data = [
[1, 4, 3],
[2, 7, 5],
[3, 2, 8],
[4, 9, 1]
]
column_to_sort = 1 # 要按照哪一列排序
# 按照指定列降序排序
sorted_data = sort_by_column(data, column_to_sort)
# 找到最大值对应的所有行
max_value = sorted_data[0][column_to_sort]
rows_with_max_value = [row for row in sorted_data if row[column_to_sort] == max_value]
# 输出结果
print("按照第", column_to_sort, "列降序排序的结果:")
for row in sorted_data:
print(row)
print("最大值对应的所有行:")
for row in rows_with_max_value:
print(row)
在上述代码中,sort_by_column
函数用于按照指定列进行排序。然后,我们使用这个函数对数据进行排序,并找到最大值对应的所有行。最后,输出结果以验证代码的正确性。