<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Post processing of data in a csv file using script in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Post-processing-of-data-in-a-csv-file-using-script/m-p/107414#M39142</link>
    <description>This gives a good foundation to solve the problem</description>
    <pubDate>Tue, 22 Jan 2019 03:58:58 GMT</pubDate>
    <dc:creator>jojmp</dc:creator>
    <dc:date>2019-01-22T03:58:58Z</dc:date>
    <item>
      <title>Post processing of data in a csv file using script</title>
      <link>https://community.jmp.com/t5/Discussions/Post-processing-of-data-in-a-csv-file-using-script/m-p/107039#M39086</link>
      <description>&lt;P&gt;I have a folder with mutiple csv files having similar data structure&amp;nbsp; whose data I need to process and store the results in a new file.&lt;BR /&gt;Each&amp;nbsp;csv file has 2 columns, I need to process the data in the second column as follows:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Name the second column as &lt;STRONG&gt;items&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;Perform the following operation on all rows creating a new column x with the following formula :36 + -19.5 * :items+ 49.99 *:&lt;SPAN&gt;items&lt;/SPAN&gt;* :&lt;SPAN&gt;items&lt;/SPAN&gt;* :&lt;SPAN&gt;items&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Perform the following operation on all rows&amp;nbsp;of column x creating column y:&lt;BR /&gt;Mean( :x[Index( Row() - 4, Row() )] )&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Find the mean and max of column y&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Store the value mean and max into the file and repeat the same procedure for other files as well&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;Pfa sample csv file.&lt;BR /&gt;I am tring something as below but since just a beginner so culd yu please help&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// 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 &amp;lt; 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 &amp;lt;&amp;lt; Set Name( files[i] );
 
 
//I concatenated all the files in one jmp file and close it each time.
dt &amp;lt;&amp;lt; Concatenate( Data Table( dt1 ), "Append to first table" );
Close( dt1 );
 
　
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Fri, 09 Jun 2023 23:25:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Post-processing-of-data-in-a-csv-file-using-script/m-p/107039#M39086</guid>
      <dc:creator>jojmp</dc:creator>
      <dc:date>2023-06-09T23:25:37Z</dc:date>
    </item>
    <item>
      <title>Re: Post processing of data in a csv file using script</title>
      <link>https://community.jmp.com/t5/Discussions/Post-processing-of-data-in-a-csv-file-using-script/m-p/107063#M39089</link>
      <description>&lt;P&gt;If you are just starting out, you should take this in stages, understanding how each part works. Use 'Help &amp;gt; Scripting Index' and 'Help &amp;gt; Books &amp;gt; Scripting Guide' to look things up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code below should get you started, and you may be able to do the rest. You will need to be more presise about what you mean by 'store the value . . . into the file'.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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&amp;gt;=1, f--, if(!endsWith(uppercase(files[f]), ".CSV"), removeFrom(files, f)));

// Process each file - Incomplete!
for(f = 1, f &amp;lt;= NItems(files), f++,
	thisTable = openMyCSV(dir||files[f]);
	thisTable &amp;lt;&amp;lt; newColumn("x", Numeric, Continuous, Formula(36 + -19.5 * :items + 49.99 *:items* :items* :items));
	);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Jan 2019 14:26:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Post-processing-of-data-in-a-csv-file-using-script/m-p/107063#M39089</guid>
      <dc:creator>ian_jmp</dc:creator>
      <dc:date>2019-01-18T14:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: Post processing of data in a csv file using script</title>
      <link>https://community.jmp.com/t5/Discussions/Post-processing-of-data-in-a-csv-file-using-script/m-p/107361#M39117</link>
      <description>&lt;P&gt;This code was very helpful for me to get started.&amp;nbsp;The below code perfectly works. By storing I mean I need to create a summary table that contains the mean and max of the column av of each csv file, how can I do that?&lt;/P&gt;&lt;P&gt;I tried the using :&amp;nbsp;dt &amp;lt;&amp;lt; Add Rows( {MovAvgMean = &lt;SPAN&gt;Mean(:av)&lt;/SPAN&gt;, MovAvgMax = Max(:av)} ); // single list&lt;/P&gt;&lt;P&gt;But it does not work as I get error&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name Unresolved: av{1} in access or evaluation of 'av' , :av/*###*/&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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 &amp;lt;&amp;lt; New Column( "MovAvgMean", Numeric );
dt &amp;lt;&amp;lt; 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&amp;gt;=1, f--, if(!endsWith(uppercase(files[f]), ".CSV"), removeFrom(files, f)));

// Process each file - Incomplete!
for(f = 1, f &amp;lt;= NItems(files), f++,
	thisTable = openMyCSV(dir||files[f]);
	thisTable &amp;lt;&amp;lt; newColumn("x", Numeric, Continuous, Formula(36 + -19.5 * :items + 49.99 *:items* :items* :items));
	thisTable &amp;lt;&amp;lt; newColumn("av", Numeric, Continuous, Formula(Mean( :x[Index( Row() - 9, Row() )] )));
	dt &amp;lt;&amp;lt; Add Rows( {MovAvgMean =Mean(:av), MovAvgMax = Max(:av)} ); // single list
	);
	
// Make the summary table



	&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jan 2019 16:10:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Post-processing-of-data-in-a-csv-file-using-script/m-p/107361#M39117</guid>
      <dc:creator>jojmp</dc:creator>
      <dc:date>2019-01-21T16:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: Post processing of data in a csv file using script</title>
      <link>https://community.jmp.com/t5/Discussions/Post-processing-of-data-in-a-csv-file-using-script/m-p/107363#M39118</link>
      <description>&lt;P&gt;You are oh so close.......&lt;/P&gt;
&lt;P&gt;You appeared to be moving towards putting into a list, the statistics that you want after each csv is read in.&amp;nbsp; Your syntax for doing that is incorrect, and in my opinion, you do not have to put the values into a list, but rather, put them directly into your summary table.&amp;nbsp; Also, when calculating statistics on a column, you need to use the column form of the statistic (i.e. Col Max() ).&amp;nbsp; Finally, if once you have finished processing of the csv file, you do not have a need for it to continue to hang around, you can simple close it.&amp;nbsp; I added in a line that would do that, but I commented it out.&amp;nbsp; Just remove the // if you want it to take effect.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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 &amp;lt;&amp;lt; New Column( "MovAvgMean", Numeric );
dt &amp;lt;&amp;lt; 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 &amp;gt;= 1, f--,
	If( !Ends With( Uppercase( files[f] ), ".CSV" ),
		Remove From( files, f )
	)
);

// Process each file - Incomplete!
For( f = 1, f &amp;lt;= N Items( files ), f++,
	thisTable = openMyCSV( dir || files[f] );
	thisTable &amp;lt;&amp;lt; New Column( "x",
		Numeric,
		Continuous,
		Formula( 36 + -19.5 * :items + 49.99 * :items * :items * :items )
	);
	thisTable &amp;lt;&amp;lt; 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 &amp;lt;&amp;lt; run formulas; 
	
	// Add the summary statistics to the summary table
	dt &amp;lt;&amp;lt; Add Rows( 1 );
	dt:MovAvgMean[N Rows( dt )] = Col Mean( thisTable:av );
	dt:MovAvgMax[N Rows( dt )] = Col Max( thisTable:av );
	
	// Close( thisTable, nosave );
);
	
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jan 2019 11:11:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Post-processing-of-data-in-a-csv-file-using-script/m-p/107363#M39118</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2019-01-21T11:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: Post processing of data in a csv file using script</title>
      <link>https://community.jmp.com/t5/Discussions/Post-processing-of-data-in-a-csv-file-using-script/m-p/107413#M39141</link>
      <description>Thanks for optimizing and solving the error, very helpful!!</description>
      <pubDate>Tue, 22 Jan 2019 03:57:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Post-processing-of-data-in-a-csv-file-using-script/m-p/107413#M39141</guid>
      <dc:creator>jojmp</dc:creator>
      <dc:date>2019-01-22T03:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: Post processing of data in a csv file using script</title>
      <link>https://community.jmp.com/t5/Discussions/Post-processing-of-data-in-a-csv-file-using-script/m-p/107414#M39142</link>
      <description>This gives a good foundation to solve the problem</description>
      <pubDate>Tue, 22 Jan 2019 03:58:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Post-processing-of-data-in-a-csv-file-using-script/m-p/107414#M39142</guid>
      <dc:creator>jojmp</dc:creator>
      <dc:date>2019-01-22T03:58:58Z</dc:date>
    </item>
  </channel>
</rss>

