将数据导入 Jmp你好,
我正在开发定期数据的 JMP 分析。 我有一个 Excel 宏,每周都会在特定文件夹中生成一个新的 CSV。 我仍然是 JMP 的一个非常基础的玩家,因此不需要社区的支持来帮助我构建脚本来执行此活动。 我确实尝试四处搜索但没有找到任何解决方案。 CSV 文件有 19 列(带标题)。 如果出现问题,我可以从 CSV 中删除标题行。 任何人都可以帮助我编写一个脚本代码解决方案,帮助我将文件自动导入到 JMP 中的父数据表中,以便我可以运行其他只能评估数据的脚本。
回复:将数据导入 Jmp感谢您的回复txnelson。 这是“在线趋势数据聚合”日志文件中的内容。 (这是我运行脚本时打开的文件)
/*:
//:*/
// This script will concatenate cleaned online data files from APPLIKON controllers to a master table.
// Define function to open .xlsx files
DataUpdate = Function({filepath},
Open(
filepath,
Worksheets( "Data" ),
Use for all sheets( 0 ),
Concatenate Worksheets( 0 ),
Create Concatenation Column( 0 ),
Worksheet Settings(
1,
Has Column Headers( 1 ),
Number of Rows in Headers( 1 ),
Headers Start on Row( 1 ),
Data Starts on Row( 2 ),
Data Starts on Column( 1 ),
Data Ends on Row( 0 ),
Data Ends on Column( 0 ),
Replicated Spanned Rows( 1 ),
Replicated Spanned Headers( 0 ),
Suppress Hidden Rows( 1 ),
Suppress Hidden Columns( 1 ),
Suppress Empty Columns( 1 ),
Treat as Hierarchy( 0 ),
Multiple Series Stack( 0 ),
Import Cell Colors( 0 ),
Limit Column Detect( 0 ),
Column Separator String( "-" )
)
)
);
//Define path to where .xlsx files are stored (location where this script is stored)
path = get default directory();
//Open Running Table (Online Trend Data Aggregated.jmp) - assuming in same directory as .xlsx files (could change path to wherever)
dt_running = Open(path||"Online Trend Data Aggregated.jmp");
//Get List of Files in Directory
files = Files In Directory(path);
//Remove any files from the list that are not .xlsx or do not contain "APPLIKON" in file name
for(i=N Items(files),i>=1,i--,
If(contains(files[i],".xlsx") == 0 | contains(files[i],"APPLIKON") == 0, Remove From(files,i));
);
//Get max(File Date) in running table to determine which files need to be appended
max_date = max(dt_running:File Date << Get Values);
//Extract Dates from File Names and determine if date is > max_date from running table
dates = {};
update_files = {};
for(i=1, i<=N Items(files),i++,
word_list = Words(files[i],"-"); //breaks out file name into words delimited by hyphens
temp_date = informat(trim(word_list[1]||"/"||word_list[2]||"/"||word_list[3]),"m/d/y"); //first 3 words are month, day, year - concatenat them separated by "/"
if(temp_date > max_date,
Insert Into(dates,temp_date);
Insert Into(update_files,files[i])
)
);
//Import selected files, add File Date column, and concatenate to running table
for(i=1,i<=N Items(update_files),i++,
dt_temp = DataUpdate(path||update_files[i]);
dt_temp << New Column("File Date", format("m/d/y"), Set Values(J(N Row(dt_temp),1,dates[i])));
dt_temp << Go To(:File Date) << Move Selected Column(To first);
dt_running << Concatenate( dt_temp, Append to First Table(1));
Close(dt_temp,nosave);
);
dt_running << Clear Column Selection;
/*:
Scriptable[]回复:将数据导入 Jmp当您只运行该文件而不使用调试器时,您会在日志中看到哪些语句?回复:将数据导入 Jmp你好,
我正在寻找与原始海报相同的解决方案!
我复制了该脚本并对其进行了修改以满足我的需要(包括上面的建议,即从 JMP 本身复制并粘贴导入脚本,而不是原始解决方案所提供的脚本。)
...但由于某种原因它不起作用。
该脚本确实打开 JMP 文件“在线趋势数据聚合”,然后停止且不执行任何操作。 之后会发生什么?
调试器运行整个过程,我收到的唯一消息是在右上角,它显示“程序执行已终止”
任何见解都非常感激。 脚本如下:
// This script will concatenate cleaned online data files from APPLIKON controllers to a master table.
// Define function to open .xlsx files
DataUpdate = Function({filepath},
Open(
filepath,
Worksheets( "Data" ),
Use for all sheets( 0 ),
Concatenate Worksheets( 0 ),
Create Concatenation Column( 0 ),
Worksheet Settings(
1,
Has Column Headers( 1 ),
Number of Rows in Headers( 1 ),
Headers Start on Row( 1 ),
Data Starts on Row( 2 ),
Data Starts on Column( 1 ),
Data Ends on Row( 0 ),
Data Ends on Column( 0 ),
Replicated Spanned Rows( 1 ),
Replicated Spanned Headers( 0 ),
Suppress Hidden Rows( 1 ),
Suppress Hidden Columns( 1 ),
Suppress Empty Columns( 1 ),
Treat as Hierarchy( 0 ),
Multiple Series Stack( 0 ),
Import Cell Colors( 0 ),
Limit Column Detect( 0 ),
Column Separator String( "-" )
)
)
);
//Define path to where .xlsx files are stored (location where this script is stored on a network drive)
path = get default directory();
//Open Running Table (Online Trend Data Aggregated.jmp) - assuming in same directory as .xlsx files (could change path to wherever)
dt_running = Open(path||"Online Trend Data Aggregated.jmp");
//Get List of Files in Directory
files = Files In Directory(path);
//Remove any files from the list that are not .xlsx or do not contain "APPLIKON" in file name
for(i=N Items(files),i>=1,i--,
If(contains(files[i],".xlsx") == 0 | contains(files[i],"APPLIKON") == 0, Remove From(files,i));
);
//Get max(File Date) in running table to determine which files need to be appended
max_date = max(dt_running:File Date << Get Values);
//Extract Dates from File Names and determine if date is > max_date from running table
dates = {};
update_files = {};
for(i=1, i<=N Items(files),i++,
word_list = Words(files[i],"-"); //breaks out file name into words delimited by hyphens
temp_date = informat(trim(word_list[1]||"/"||word_list[2]||"/"||word_list[3]),"m/d/y"); //first 3 words are month, day, year - concatenat them separated by "/"
if(temp_date > max_date,
Insert Into(dates,temp_date);
Insert Into(update_files,files[i])
)
);
//Import selected files, add File Date column, and concatenate to running table
for(i=1,i<=N Items(update_files),i++,
dt_temp = DataUpdate(path||update_files[i]);
dt_temp << New Column("File Date", format("m/d/y"), Set Values(J(N Row(dt_temp),1,dates[i])));
dt_temp << Go To(:File Date) << Move Selected Column(To first);
dt_running << Concatenate( dt_temp, Append to First Table(1));
Close(dt_temp,nosave);
);
dt_running << Clear Column Selection;
回复:将数据导入 Jmp@cwillden
这很有魅力,我真的很感谢你的支持。 这能够在几秒钟内处理我在独特的 CSV 文件中的数十万行,谢谢!!!回复:将数据导入 Jmp以下是您可以如何执行此操作的示例。假设 CSV 文件有 2 列,X1 和 X2。我创建了 2 个示例 csv 文件(“3-29-18 - My Data.csv”和“4-5-18 - My Data.csv”)。我还有一个正在运行的 jmp 表,保存在与 CSV 文件相同的目录中。
以下脚本将在目录中查找所有文件,过滤掉任何非 CSV 文件和文件名中不含“我的数据”的文件。然后,它获取已导入运行表的文件的最新日期。然后,它循环遍历满足先前条件的文件列表,并从文件名中提取日期。如果该日期大于运行表中的最大日期,则会将该文件放入文件列表中以追加到运行表中。
之后,它循环遍历我们确定需要附加的文件,首先打开它们,然后添加文件日期列,然后将文件连接到运行表。
//Define function to open up your CSV files - will need to be modified for your own CSV file
MyCSVImporter = Function({filepath},
Open(
filepath,
columns(
New Column( "X1", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "X2", Numeric, "Continuous", Format( "Best", 12 ) )
),
Import Settings(
End Of Line( CRLF, CR, LF ),
End Of Field( Comma, CSV( 0 ) ),
Strip Quotes( 1 ),
Use Apostrophe as Quotation Mark( 0 ),
Use Regional Settings( 0 ),
Scan Whole File( 1 ),
Treat empty columns as numeric( 0 ),
CompressNumericColumns( 0 ),
CompressCharacterColumns( 0 ),
CompressAllowListCheck( 0 ),
Labels( 1 ),
Column Names Start( 1 ),
Data Starts( 2 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
)
);
//Define path to where csv files are stored
path = "$DOCUMENTS/temp/";
//Open Running Table (RunningTable.jmp) - assuming in same directory as CSV files (could change path to wherever)
dt_running = Open(path||"RunningTable.jmp");
//Get List of Files in Directory
files = Files In Directory(path);
//Remove any files from the list that are not .csv or do not contain "My Data" in file name
for(i=N Items(files),i>=1,i--,
If(contains(files[i],".csv") == 0 | contains(files[i],"My Data") == 0, Remove From(files,i));
);
//Get max(File Date) in running table to determine which files need to be appended
max_date = max(dt_running:File Date << Get Values);
//Extract Dates from File Names and determine if date is > max_date from running table
dates = {};
update_files = {};
for(i=1, i<=N Items(files),i++,
word_list = Words(files[i],"-"); //breaks out file name into words delimited by hyphens
temp_date = informat(trim(word_list[1]||"/"||word_list[2]||"/"||word_list[3]),"m/d/y"); //first 3 words are month, day, year - concatenat them separated by "/"<BR />
if(temp_date > max_date,
Insert Into(dates,temp_date);
Insert Into(update_files,files[i])
)
);
<BR />//Import selected files, add File Date column, and concatenate to running table
for(i=1,i<=N Items(update_files),i++,
dt_temp = MyCSVImporter(path||update_files[i]);
dt_temp << New Column("File Date", format("m/d/y"), Set Values(J(N Row(dt_temp),1,dates[i])));
dt_temp << Go To(:File Date) << Move Selected Column(To first);
dt_running << Concatenate( dt_temp, Append to First Table(1));
Close(dt_temp,nosave);
);
dt_running << Clear Column Selection;
在此示例中,RunningTable 中已包含 3-29-18 数据,因此它只会追加 4-5-18 数据。
回复:将数据导入 Jmp谢谢!
@uday_guntupalli是的,数据将始终采用相同的格式、相同的列数和相同的标题。
我已经将数据导入 JMP 一次。 问题是每周从将生成的新 CSV 文件自动更新此数据。 每周都会生成一个新的 CSV 文件,文件名为“<日期> - 我的数据”。 我希望 JMP 每次都将此数据导入到我的父文件中。 如何编写命令让 JMP 自动转到文件夹目录并从列表中选择最新文件并导入该数据并将其修改到运行表。
回复:将数据导入 Jmp只是澄清一点@uday_guntupalli回复:
它将提供这样的界面。 您可能需要选择“带预览的数据”,以便您了解正在导入的内容并可以进行自定义。 完成导入后,转到导入的数据表。查看数据表显示左侧的表面板。 右键单击“源”项前面的绿色三角形,它将提供一个“编辑”选项,您可以在其中看到生成的 JMP 脚本。然后,您将能够将该脚本剪切并粘贴到每周脚本开发的开头。
回复:将数据导入 Jmp你好@尼尔D ,
如果您可以第一次手动导入脚本,JMP 将为您生成脚本。生成的表将有一个脚本“Source”,它准确显示如何使用 JSL 导入数据。
如果 JMP 未正确导入 .csv 文件,请执行以下操作。像往常一样执行“文件”>“打开”(或 Ctrl + O)(如果需要,将“打开数据文件”窗口中的文件类型更改为“文本文件”),导航到 .csv 文件并选择它。在打开 .csv 之前,您应该会看到一些单选按钮,为您提供打开文件的不同选项。一是“带预览的数据”。选择该选项后,您将有机会在将数据导入 JMP 之前更改导入设置。

回复:将数据导入 Jmp@尼尔D ,
文件的格式总是相同吗?即相同的列名和相同类型的数据?
最简单的方法是让 JMP 为您提供用于导入文件的脚本 - 这样您就可以自定义选择并重复使用该脚本。
文件==>打开==>选择你想要的文件
它将提供这样的界面。 您可能需要选择“带预览的数据”,以便您了解正在导入的内容并可以进行自定义。 完成后,单击绿色三角形,它将提供一个“编辑”选项,您可以在其中看到生成的 JMP 脚本
