여러 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를 쌓으면 400,000행 출력이 생성됩니다. 이러한 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 파일을 통해 스크립트를 순환하는 방법코드에서 파일 이름 목록에 파일 이름 대신 파일 목록을 사용하려는 것 같습니다. 거의 끝 부분에 있습니다.
Re: 여러 csv 파일을 통해 스크립트를 순환하는 방법이걸 보았지만 내 요구에 맞지 않는 것 같습니다. 그러면 개별 jmp dt가 열립니다. 열 번호는 각 프로세스 파일의 시간 범위를 기반으로 동적입니다.
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] );Re: 여러 csv 파일을 통해 스크립트를 순환하는 방법다중 파일 가져오기도 확인하세요. CSV 파일을 로드하고 동일한 열이 있으면 연결하며 선택적으로 파일 이름 열을 추가할 수 있습니다.
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>