python - 在 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)
我的代码哪里出错了,我该怎么办?
解决方案
推荐阅读
- javascript - 将 input:file 连接到 input:text 和 input:button 以选择文件
- android - 房间和重复的主键列
- reactjs - Redux 传奇。无法在 promise 'catch' 块中使用 yield
- nginx - 使用 Nginx 转发 Keberos 票证
- r - R:从 xts 对象导出特定值类
- javascript - Vue-tables-2 create .pdf (pdfmake) 'malformed table row' 错误
- postgresql - PostgreSQL 如何根据另一个表上的插入在一个表上的列上创建 AVG
- collections - 如何在 Waterline 独立中定义基本类型的集合?
- vba - VBA If/Else 语句根据列数复制和粘贴数据
- powershell - 在 foreach UNIQUE 中创建“cmd /c”命令