4
$\begingroup$

I want to import an excel .csv file and ListPlot the data.

file = Import["Desktop/PP_1039.CSV", "Data"]

But I get this data :

(*{{"0.0472;120.9091"}, {"0.0454;113.0303"}, {"0.0441;106.6667"},
  {"0.0442;106.6667"}, {"0.0437;103.3333"}, {"0.0425;95.1515"}, 
  {"0.0409;83.6364"}, {"0.0387;72.7273"}, {"0.0354;59.697"}, 
 {"0.0317;45.7576"}, {"0.0275;34.8485"}, {"0.0234;24.8485"}, 
 {"0.0155;12.1212"}, {"0.0115;6.6667"}, {"0.0072;2.7273"},    
 {"0.0031;2.1212"}}  *)

So I'd like to delete the " and to replace ; with ,

$\endgroup$
  • 1
    $\begingroup$ StringReplace? $\endgroup$ – Henrik Schumacher Feb 1 at 9:32
  • 4
    $\begingroup$ Just be aware that ToExpression (i.e. the answer you accepted) will not handle all number formats that are allowed (and often present) in CSV files, such as 123.4e5. $\endgroup$ – Szabolcs Feb 1 at 11:50
  • $\begingroup$ You could try importing the file via ReadList[file, Expression] $\endgroup$ – user170231 Feb 1 at 23:15
4
$\begingroup$
ToExpression[StringReplace[ToString[file], ";" -> ","]]

{{0.0472, 120.9091}, {0.0454, 113.0303}, {0.0441, 106.6667}, {0.0442, 106.6667}, {0.0437, 103.3333}, {0.0425, 95.1515}, {0.0409, 83.6364}, {0.0387, 72.7273}, {0.0354, 59.697}, {0.0317, 45.7576}, {0.0275, 34.8485}, {0.0234, 24.8485}, {0.0155, 12.1212}, {0.0115, 6.6667}, {0.0072, 2.7273}, {0.0031, 2.1212}}

$\endgroup$
11
$\begingroup$

Import as Table instead of CSV, and set the "FieldSeparators" option.

ImportString[
 "1;2
 3;4", 
 "Table", "FieldSeparators" -> {";"}]

(* {{1, 2}, {3, 4}} *)

"Table" is a generalization of CSV, TSV, etc. where you can customize the delimiters and separators.

$\endgroup$
4
$\begingroup$
ToExpression[file /. {a_String} :> StringSplit[a, ";"]]
$\endgroup$
0
$\begingroup$

Method One: 1) Caution: Make a copy of your original file and then proceed. Just in case it doesn't work. :) 2) Select all the contents in which you need to make the changes. 3) Use "Replace" command to replace whatever with whatever you want. (Replace " with blank space and ; with ,) 4) That it.

Method Two: 1) Caution: Make a copy of your original file and then proceed. Just in case it doesn't work. :) 2) Copy all the contents in Word. It will most probably be imported as a table. 3) Select all the contents in which you need to make the changes. 4) Use "Replace" command to replace whatever with whatever you want. (**Replace " with ***blank space* and ; with ,) 5) Select all the contents from word that are in table and paste it in Excel again.

$\endgroup$
  • $\begingroup$ In what sense is this solution related to Mathematica? $\endgroup$ – Henrik Schumacher Feb 2 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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