-3
$\begingroup$

Lets say I have 100 CSV files of two columns data in each file, and I want to calculate the average of the 2nd column of each CSV file and then save all all these 100 averaged values in one CSV file (in one column) and then plot this CSV file of averaged values with respect to another CSV file having one column (100 datas in it)

Please give me a mathematica code for this.

$\endgroup$

closed as off-topic by m_goldberg, MarcoB, Henrik Schumacher, Carl Lange, C. E. May 1 at 13:00

  • The question does not concern the technical computing software Mathematica by Wolfram Research. Please see the help center to find out about the topics that can be asked here.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    $\begingroup$ I'm voting to close this question as off-topic because there is no well-posed question in this post; the OP is simply asking for somebody to act as a free coding service. $\endgroup$ – m_goldberg Apr 30 at 9:30
1
$\begingroup$

Assume you have a list, FileNameList, of your file names, and that they all explicitly have .csv as the extension.

data=Import/@FileNameList;
averages=Mean/@(data[[All, All, 2]]);
Export["averages.csv",averages]
xdata=Import["otherfile.csv"];
ListPlot[Transpose[{xdata,averages}]]

Edited to add:

enter image description here

$\endgroup$
  • $\begingroup$ Thank you Sir, I will try it out $\endgroup$ – Dame Chrm Apr 30 at 6:21
  • $\begingroup$ Sir, I cannot import all the CSV datas, I can import one CSV file $\endgroup$ – Dame Chrm Apr 30 at 10:26
  • $\begingroup$ Ok, then something like: data=Table[Import[FileNameList[[i]]],{i,Length[FileNameList]}] should work. I don't have your data files, so I couldn't test. $\endgroup$ – Kevin Ausman May 1 at 0:31
  • $\begingroup$ Just made some example files and my original version works. FileNameList={"test1.csv","test2.csv","test3.csv"}; data=Import/@FileNameList; $\endgroup$ – Kevin Ausman May 1 at 20:00
  • $\begingroup$ Yes, I did just that (files in FileNameList folder), it does read the files in the output, but while doing (averages=Mean/@(data[[All, All, 2]])), instead of giving list of average values of each CSV files, it instead give a list of words as "mean striongs, meanstrings...." $\endgroup$ – Dame Chrm May 2 at 9:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.