抓住Excel列中的最高值,并使用Python / Pandas显示行名

时间:2018-08-16 16:01:19

标签: python python-3.x python-2.7 pandas numpy

我对Python和Pandas还是很陌生,想看看使用pandas是否可行。我已经在线阅读了最好的方法是使用idxmax。

我正在尝试做的事情: 搜索一个名为“ Sample”的Excel文件-检查“ Difference”列,找到最大值->抓住“ Metric”名称,并显示到记事本文件/浏览器中。下面是参考图片。
enter image description here

这是我在网上看到的一小段代码,对于执行此操作的任何帮助将不胜感激。

代码:

metric_column = Metric[:,1].astype(int)
metric = metric_column[np.argmax(Difference)]

1 个答案:

答案 0 :(得分:3)

这应该做到

private void copyAssets() {
    AssetManager assetManager = getAssets();
    String[] files = null;
    try {
        files = assetManager.list("MyFolder");
    } catch (IOException e) {
        Log.e("tag", "Failed to get asset file list.", e);
    }
    if (files != null) for (String filename : files) {
        InputStream in = null;
        OutputStream out = null;
        try {
          in = assetManager.open("MyFolder/"+filename);
          File outFile = new File(getExternalFilesDir(null), filename);
          if (!(outFile.exists())) {// File does not exist...
                out = new FileOutputStream(outFile);
                copyFile(in, out);
          }
        } catch(IOException e) {
            Log.e("tag", "Failed to copy asset file: " + filename, e);
        }     
        finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    // NOOP
                }
            }
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                    // NOOP
                }
            }
        }  
    }
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
    byte[] buffer = new byte[1024];
    int read;
    while((read = in.read(buffer)) != -1){
      out.write(buffer, 0, read);
    }
}