首页 > 解决方案 > 在 Python Pandas 的 Jupyter Lab 的主文件夹中找不到最新的 csv 文件的问题?

问题描述

我正在尝试在 Jupyter Lab 的文件夹中检查 Python Pandas 中哪个 .csv 是最新的,我正在使用如下代码:

import os
path = "Data/"
csvs = [x for x in os.listdir(path) if os.path.isfile(x) and x.endswith(".csv")]
most_recent = max(csvs, key = lambda x: os.stat(os.path.join(path, x)).st_mtime)

print(most_recent)

然而,它会产生这样的错误:ValueError: max() arg is an empty sequence在第 4 行“most_recent ....”

但是,有趣的是,当我在 Jupyter Lab 的主文件夹中执行此操作时,它可以工作(代码如下):

import os
path = "/home/dsl/"
csvs = [x for x in os.listdir(path) if os.path.isfile(x) and x.endswith(".csv")]
most_recent = max(csvs, key = lambda x: os.stat(os.path.join(path, x)).st_mtime)

print(most_recent)

我的代码哪里出错了,我该怎么办?

标签: pythonpandasoperating-systemjupyter-lab

解决方案


推荐阅读