如何按每行的值4rth值排列数组,从最高到最低?

时间:2014-11-29 02:34:50

标签: python arrays sorting

如何按每行的值4rth值排列数组,从最高到最低?我对Python很陌生,所以我缺乏很多知识。

输入形状

panite,1,1800
ruby,2,100
diamond,0.75,900
emerald,3,250
amethyst,2,50
opal,1,300
sapphire,0.5,750
benitoite,1,2000
malachite,1,60

我的Python脚本

#!/usr/bin/python3
import sys
import numpy as np


def vault(dataFile):
    vault = []

    for l in dataFile.readlines():      
        attribute = l.split(",")
        vault.append(str(attribute[0]))
        vault.append(float(attribute[1]))
        vault.append(int(attribute[2]))
        vault.append(int(attribute[2])/float(attribute[1]))
    Vault = np.array(vault).reshape(-1,4)
    return(Vault)

def main():
    fileFound = False
    while not fileFound:
        fileName = input("File name containing jewel data: ")
        try:
            dataFile = open(fileName, "r")
            fileFound = True
        except:
            print("Could not find that file -- try again")
    knapsackCapacity = 5.00
    print (vault(dataFile))

main()

0 个答案:

没有答案