在Palantir Foundry中如何将NAS文件夹的Excel文件列表转为可用数据集?
在Palantir Foundry中将NAS连接的XLSX文件列表转为流水线可用数据集
确认NAS连接配置
先在Foundry的Data Connections页面检查你的NAS连接,确保已启用文件扫描功能,能正常识别目标文件夹下的XLSX文件。创建File Transform处理文件
在Foundry中新建一个Python类型的Transform,通过文件系统API读取NAS文件并转换为数据集:from transforms.api import transform, Input, Output from foundry.filesystem import FileSystem import pandas as pd @transform( output=Output("/your/workspace/path/output_dataset"), ) def combine_xlsx(ctx, output): # 替换为你的NAS连接名称和目标文件夹路径 nas_fs = FileSystem.get("your-nas-connection-id") xlsx_paths = [file for file in nas_fs.ls("/target/nas/folder") if file.endswith(".xlsx")] # 读取并合并所有XLSX文件 data_frames = [] for path in xlsx_paths: with nas_fs.open(path, "rb") as file: df = pd.read_excel(file, engine="openpyxl") data_frames.append(df) combined_data = pd.concat(data_frames, ignore_index=True) # 写入输出数据集 output.write_dataframe(combined_data)配置Python依赖
在Transform的requirements.txt中添加必要依赖:pandas>=1.5.0 openpyxl>=3.0.0验证与调度
提交Transform运行,验证输出数据集的内容是否符合预期。如果NAS文件会定期更新,可在Transform的调度设置中配置定时任务,实现数据集自动同步。
内容的提问来源于stack exchange,提问作者Jresearcher
相关产品推荐
相关产品推荐

