스크립트를 사용하여 csv 파일에서 데이터의 사후 처리나는 데이터를 처리하고 새로운 파일에 결과를 저장해야하는 유사한 데이터 구조를 갖는 다중 CSV 파일이 담긴 폴더가 있습니다.
각 csv 파일에는 2 개의 열이 있습니다. 다음과 같이 두 번째 열의 데이터를 처리해야합니다.
- 두 번째 열의 이름을 항목
- 다음 수식을 사용하여 새 열 x를 만드는 모든 행에 대해 다음 작업을 수행하십시오. 36 + -19.5 * : items + 49.99 * : 항목 * : 항목 * : 항목
- 열 x 열 y를 만드는 모든 행에 대해 다음 작업을 수행하십시오.
Mean (: x [Index (Row () - 4, Row ())]) - 열의 평균과 최대 값을 구하라.
- 평균값과 최대 값을 파일에 저장하고 다른 파일에도 동일한 절차를 반복하십시오. PFA 샘플 CSV 파일.
나는 아래처럼 뭔가를 tring 오전하지만 그냥 초보자 그래서 유치 도와주세요 제발 도와주세요
// Read all the file names
files = Files In Directory( "C:\Users\MyUserName\Documents\My Data\" );
X = N Items( files );
Y = "C:\Users\MyUserName\Documents\My Data\";
//stores the mean and max value of each file
dt = New Table( "My data file");
For( i = 1, i < X, i++,
//open jmp files for each csv files.
dt1 = Open(
Y || files[i],
//Code to add column name and the find mean and max
);
dt1 << Set Name( files[i] );
//I concatenated all the files in one jmp file and close it each time.
dt << Concatenate( Data Table( dt1 ), "Append to first table" );
Close( dt1 );
);
제목 : Re : 스크립트를 사용하여 CSV 파일에 데이터 처리 후 처리이것은 문제를 해결하기위한 좋은 기초를 제공합니다.제목 : Re : 스크립트를 사용하여 CSV 파일에 데이터 처리 후 처리오류를 최적화하고 해결해 주셔서 감사합니다. 매우 유용합니다 !!제목 : Re : 스크립트를 사용하여 CSV 파일에 데이터 처리 후 처리너 오 너무 가까워 .......
당신은 각 csv가 읽힌 후에 원하는 목록을 넣는쪽으로 움직이는 것처럼 보였습니다. 그 일을하기위한 구문은 정확하지 않으며, 제 생각에는 값을 목록에 넣을 필요는 없으며 직접 요약 테이블에 넣으십시오. 또한 열에 대한 통계를 계산할 때 통계의 열 형식 (예 : 콜 맥스 ()). 마지막으로 csv 파일 처리가 끝나면 계속해서 처리 할 필요가 없습니다. 간단히 닫을 수 있습니다. 나는 그것을 할 줄을 추가했지만, 나는 그것을 주석 처리했다. // 적용하려면 // 제거하십시오.
Names Default To Here( 1 );
// Use a function to open a .CSV file: Given the path to such a file, returns a reference to the resulting table
openMyCSV = Function( {path2File},
{Default Local},
dt = Open(
path2File,
columns(
New Column( "column 1", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "items", 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( 0 ),
Column Names Start( 1 ),
Data Starts( 1 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
)
);
// Start your summary table
dt = New Table( "My summary file" );
dt << New Column( "MovAvgMean", Numeric );
dt << New Column( "MovAvgMax", Numeric );
// Put all the .csv files to process into a list
dir = Pick Directory(
"Directory containing your csv files",
"C:\Users\shilpajo\Documents\PV\KT\LIMC\iccMax\DIADEM\JMP\files\"
);
files = Files In Directory( dir );
For( f = N Items( files ), f >= 1, f--,
If( !Ends With( Uppercase( files[f] ), ".CSV" ),
Remove From( files, f )
)
);
// Process each file - Incomplete!
For( f = 1, f <= N Items( files ), f++,
thisTable = openMyCSV( dir || files[f] );
thisTable << New Column( "x",
Numeric,
Continuous,
Formula( 36 + -19.5 * :items + 49.99 * :items * :items * :items )
);
thisTable << New Column( "av", Numeric, Continuous, Formula( Mean( :x[Index( Row() - 9, Row() )] ) ) );
// This will insure that all formula processing is complet before the next statement is run
thisTable << run formulas;
// Add the summary statistics to the summary table
dt << Add Rows( 1 );
dt:MovAvgMean[N Rows( dt )] = Col Mean( thisTable:av );
dt:MovAvgMax[N Rows( dt )] = Col Max( thisTable:av );
// Close( thisTable, nosave );
);
제목 : Re : 스크립트를 사용하여 CSV 파일에 데이터 처리 후 처리이 코드는 시작하는 데 매우 도움이되었습니다. 아래 코드는 완벽하게 작동합니다. 저장하면 각 CSV 파일의 평균 열 수와 최대 열 수를 포함하는 요약 표를 작성해야합니다. 어떻게하면됩니까?
나는 사용을 시도 : dt << 행 추가 ({MovAvgMean = 평균 (: av) , MovAvgMax = Max (: av)}); // 단일 목록
하지만 오류가 발생하면 작동하지 않습니다.
확인되지 않은 이름 : 'av'에 대한 액세스 또는 평가에서 av {1}, : av / * ### * /
NamesDefaultToHere(1);
// Use a function to open a .CSV file: Given the path to such a file, returns a reference to the resulting table
openMyCSV =
function({path2File}, {Default Local},
dt = Open(
path2File,
columns(
New Column( "column 1", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "items", 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( 0 ),
Column Names Start( 1 ),
Data Starts( 1 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
)
);
dt = New Table( "My data file");
dt << New Column( "MovAvgMean", Numeric );
dt << New Column( "MovAvgMax", Numeric );
// Put all the .csv files to process into a list
dir = pickDirectory("Directory containing your csv files", "$DESKTOP");
files = filesInDirectory(dir);
for(f = NItems(files), f>=1, f--, if(!endsWith(uppercase(files[f]), ".CSV"), removeFrom(files, f)));
// Process each file - Incomplete!
for(f = 1, f <= NItems(files), f++,
thisTable = openMyCSV(dir||files[f]);
thisTable << newColumn("x", Numeric, Continuous, Formula(36 + -19.5 * :items + 49.99 *:items* :items* :items));
thisTable << newColumn("av", Numeric, Continuous, Formula(Mean( :x[Index( Row() - 9, Row() )] )));
dt << Add Rows( {MovAvgMean =Mean(:av), MovAvgMax = Max(:av)} ); // single list
);
// Make the summary table
제목 : Re : 스크립트를 사용하여 CSV 파일에 데이터 처리 후 처리방금 시작한 경우 단계별로 각 부분의 작동 방식을 이해해야합니다. '도움말> 스크립팅 색인'및 '도움말> 책> 스크립팅 안내서'를 사용하여 볼 수 있습니다.
아래의 코드를 시작해야하며 나머지는 수행 할 수 있습니다. '가치를 저장하는 것이 무엇을 의미하는지 더 많이 알 필요가 있습니다. . . 파일에 '.
NamesDefaultToHere(1);
// Use a function to open a .CSV file: Given the path to such a file, returns a reference to the resulting table
openMyCSV =
function({path2File}, {Default Local},
dt = Open(
path2File,
columns(
New Column( "column 1", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "items", 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( 0 ),
Column Names Start( 1 ),
Data Starts( 1 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
)
);
// Put all the .csv files to process into a list
dir = pickDirectory("Directory containing your csv files", "$DESKTOP");
files = filesInDirectory(dir);
for(f = NItems(files), f>=1, f--, if(!endsWith(uppercase(files[f]), ".CSV"), removeFrom(files, f)));
// Process each file - Incomplete!
for(f = 1, f <= NItems(files), f++,
thisTable = openMyCSV(dir||files[f]);
thisTable << newColumn("x", Numeric, Continuous, Formula(36 + -19.5 * :items + 49.99 *:items* :items* :items));
);