여러 csv 파일을 통해 스크립트를 순환하는 방법이전 게시물에 이어 다루기 힘든 csv 파일을 쌓고 형식을 지정하는 스크립트가 있습니다.
https://community.jmp.com/t5/Discussions/Help-doing-a-table-transform-and-converting-a-timestamp/td-p/303091
도움이 필요한 다음 질문은 폴더의 csv 그룹에서 반복하여 파일 이름을 열 중 하나로 캡처하여 이상적으로 쌓아 두는 방법입니다. 일명 step1, step2, step3, step4 파일.
단일 csv를 스택하면 400k 행 출력이 생성됩니다. 이 csv를 4 개 또는 8 개 또는 10 개 병합하면 충돌 위험이 있습니까?
추가로 상위 폴더의 다음 폴더를 다시 순환하여 새로운 결합 된 단계 파일을 생성 할 수 있습니까?
names default to here(1);
//Prompt to select and open an MS Excel file
dt = Open( Pick File( "Select Excel File", "C:\Users\folder\", {"Excel Files|csv;xlsx;xls", "All Files|*"}, 1, 0 ), Invisible );
// Get the column names from the data table
colNames = dt << get column names;
// Remove the 1st col from the list
remove from(colNames,1,1);
// Stack the data
dtStack = dt << Stack(
columns(
colNames
),
Source Label Column( "Label" ),
Stacked Data Column( "Data" ),
Output Table( "Stacked_Data" )
);
//label the 1st column to Lamda
:Column 1 << Set Name("Lamda");
:Lamda << Modeling Type(nominal);
// Create a new JMP DateTime column
dtStack << New Column( "Timestamp",
Numeric,
"Continuous",
Format( "d/m/y h:m:s", 26, 3 ),
Input Format( "d/m/y h:m:s", 0 ),
Formula( Informat( Word( 1, :Label, "Z" ), "d/m/y h:m:s" ) )
);
// Remove formula to convert column to static values
dtStack:Timestamp << delete formula;
// Create the Time variable column
dtstack << New Column( "Time",
Numeric,
"Continuous",
Format( "hr:m:s", 17, 3 ),
Input Format( "hr:m:s", 0 ),
Formula( Time Of Day( :Timestamp ) )
);
//Create Absolute Time column, uses if>then error checking for Lamda group changing
dtstack << New Column( "AbsTime",
Numeric,
"Continuous",
Format( "Fixed Dec", 12, 1 ),
Formula(
If( Row() == 1 | :Lamda != Lag( :Lamda ),
0,
Lag( :AbsTime ) + (:Timestamp - Lag( :Timestamp ))
)
),
);
// Remove formula to convert column to static values
dtStack:AbsTime << delete formula;
// Get rid of no longer needed "Label" column
dtStack << delete columns( "Label" );
데이터 테이블스크립팅Re : 여러 CSV 파일을 통해 스크립트를 순환하는 방법기본적으로해야 할 일은
- "Files In Directory ()를 사용하여 처리 할 파일 목록을 가져옵니다.
- 최종 데이터 테이블 (dtFinal)에 사용할 데이터 테이블 설정
- For () 루프를 사용하여 deStack 테이블을 생성하는 디렉토리에서 발견 된 모든 파일을 반복합니다.
- dtStack에 소스 열 추가
- dtStack을 dtFinal 테이블에 연결
- dtStack 및 dt 데이터 테이블 닫기
아래는 위 항목으로 수정 된 스크립트입니다.코드는 테스트되지 않았으며 파일을 읽으려면 디렉토리 등에 추가해야합니다.최종 제품을 얻을 수있는 좋은 출발점이 될 것입니다.
names default to here(1);
//Prompt to select and open an MS Excel file
//dt = Open( Pick File( "Select Excel File", "C:\Users\folder\", {"Excel Files|csv;xlsx;xls", "All Files|*"}, 1, 0 ), Invisible );
// Get a list of files from the directory
fileList = Files In Directory( <PATH to="" your="" directory=""> || fileList[i] );
// Get the column names from the data table
colNames = dt << get column names;
// Remove the 1st col from the list
remove from(colNames,1,1);
// Stack the data
dtStack = dt << Stack(
columns(
colNames
),
Source Label Column( "Label" ),
Stacked Data Column( "Data" ),
Output Table( "Stacked_Data" )
);
//label the 1st column to Lamda
:Column 1 << Set Name("Lamda");
:Lamda << Modeling Type(nominal);
// Create a new JMP DateTime column
dtStack << New Column( "Timestamp",
Numeric,
"Continuous",
Format( "d/m/y h:m:s", 26, 3 ),
Input Format( "d/m/y h:m:s", 0 ),
Formula( Informat( Word( 1, :Label, "Z" ), "d/m/y h:m:s" ) )
);
// Remove formula to convert column to static values
dtStack:Timestamp << delete formula;
// Create the Time variable column
dtstack << New Column( "Time",
Numeric,
"Continuous",
Format( "hr:m:s", 17, 3 ),
Input Format( "hr:m:s", 0 ),
Formula( Time Of Day( :Timestamp ) )
);
//Create Absolute Time column, uses if>then error checking for Lamda group changing
dtstack << New Column( "AbsTime",
Numeric,
"Continuous",
Format( "Fixed Dec", 12, 1 ),
Formula(
If( Row() == 1 | :Lamda != Lag( :Lamda ),
0,
Lag( :AbsTime ) + (:Timestamp - Lag( :Timestamp ))
)
),
);
// Remove formula to convert column to static values
dtStack:AbsTime << delete formula;
// Get rid of no longer needed "Label" column
dtStack << delete columns( "Label" );
// Add filename as a column to the data table
dtStack << new column( "Source", character, set each value( filename[i] ) );
// Concatenate to final table
dtFinal << concatenate( dtStack, append to first table(1) );
// Clean up
close( dtStack, nosave );
close( dt, nosave );
// End For() Loop
);</PATH>Re : 여러 CSV 파일을 통해 스크립트를 순환하는 방법또한 다중 파일 가져 오기를 확인하십시오. CSV 파일을로드하고 동일한 열이있는 경우 연결하며 선택적으로 파일 이름 열을 추가 할 수 있습니다.
Re : 여러 CSV 파일을 통해 스크립트를 순환하는 방법대박. 작동하는 것 같지만 첫 번째 파일 이후에 오류가 발생합니다.
"이름 미해결 : filenam} 1} 액세스 또는 'filename', filename / * ### * / 평가 중"
이견있는 사람?
또한 선택 폴더 팝업을 수행하도록 스크립트를 조정했는데 문제가 아니라고 가정합니다.
// Get a list of files from the directory
dir = Pick Directory( "Select a directory", "C:\Users\folder\");
fileList = Files In Directory( dir );
// Create a skeleton data table to end up being the combined data table
dtFinal = New Table("Final");
// Loop across all of the files found in the directory and read them in
For(i = 1, i <= N Items( fileList ), i++,
dt = open( dir || fileList[i] );