Tag Info

Hot answers tagged

10

ReadList Assuming that you want to read all fields as strings, you could set up ReadList like this: ReadList["sample.csv", Word, WordSeparators -> {",", " "}, RecordSeparators -> {"\n"}, RecordLists -> True ] Import ReadList is usually quite a bit faster, but if speed is not paramount you may find Import more convenient. It attempts to ...


10

If your data is Imported say in data then you can use data[[All,{1,2}]] to use the first column as x and the second as y value. Plotting all three data sets would be ListPlot[{data[[All, {1, 2}]], data[[All, {1, 3}]], data[[All, {1, 4}]]}] If you want to print against row index, like in yopur figure you can use ListPlot[{data[[All, 2]], data[[All, 3]], ...


8

Here is a Java-based solution, pretty fast but valid only when all your columns are numerical (double) values. First, grab and run the code for the Java reloader (The linked version should work on Windows and probably Linux, but was reported to have issues for OS X. So, Mac users may try this one instead: ...


8

Here's a much faster, purely Mathematica way than using Import to import your data: UPDATE As Leonid mentioned the previous code doesn't exactly replicate Import. The truth is I was only trying to retrieve the numerical part. Here's an updated version that tries to replicate the output from Import. readYourCSV2[file_String?FileExistsQ, n_Integer] := ...


7

Here is a function which may help: Clear[readRows]; readRows[stream_, n_] := With[{str = ReadList[stream, "String", n]}, ImportString[StringJoin[Riffle[str, "\n"]], "Table"] /; str =!= {}]; readRows[__] := $Failed; I tested on your file and it works all right (it may make sense to read rows in batches, this is much faster): n=0; str = ...


7

(*Testing ... First we generate some points*) points = Flatten[Table[{x, y, PDF[BinormalDistribution[{0, 0}, {1, 2}, .5], {x, y}]}, {x, -3, 3, .1}, {y, -3, 3, .1}], 1]; (* Now we export it as a csv *) Export["c:\\points.csv", points]; (* The file looks like this: -3.,-3.,0.0010207851317789406 -3.,-2.9,0.0010190852401957891 ...


6

ListPlot requires a list of {x,y} pairs for each data set. What Markus is showing is how to get that in the right format. For styling, read through the options for PlotStyle and PlotMarkers. For legends, you have several options: Try to use the PlotLegend Package (bleh) Roll your own with the help of MMA.SE Most helpful: Creating legends for plots with ...


6

We can use the "Numeric" option to have Import interpret all data as strings: Import["data.csv", "CSV", "Numeric" -> False] The resulting table will only contain strings. If desired, we could post-process the imported strings by applying a different parsing function to each input column (ignoring the header line for simplicity): Inner[ #2@#& , ...


6

When I use Import to import a test file consisting of the following 4 lines 10/03/13 19:04, 4, N 28/11/12 03:41, 6.2, Y # Records added 01/04/12 10/03/11 19:04, 4, N using "CSV" as the specified format Import["C:\\Users\\Sjoerd\\Desktop\\test.dat", "CSV"] I get {{"10/03/13 19:04", 4, " N"}, {"28/11/12 03:41", 6.2, " Y"}, {"# Records added ...


5

If the OutputForm of your expressions is acceptable for export you might use WriteString as follows: dat = RandomReal[{-9, 9}, {261000, 30}]; str = OpenWrite["speedtest.csv"]; WriteString[str, Row[#, ","], "\n"] & ~Scan~ dat // AbsoluteTiming Close[str]; {15.9369116, Null} The file looks like: ...


4

This function converts serial dates only since March 1st, 1990, due to the Excel bug described here: Converting Excel serial dates with NETLink convertDate[serialdate_] := If[serialdate < 61, "N/A", DatePlus[{1901, 1, 0}, serialdate - 366]] convertDate[40969.00069] {2012, 3, 1, 0, 0, 59.616} DateString@Round@% Thu 1 Mar 2012 00:01:00


3

I think you are confused on ZTransform. This expects to take an expression as a function of n, for example n^2 2^(-n). If you have just numbers, then you can't do this. You need to apply the formula itself. Assuming one-sided ZTransform, then simply write Clear[z, n] data = RandomReal[{0, 1}, 10]; Sum[data[[n + 1]] z^(-n), {n, 0, Length[data] - 1}] ...


3

This is a job for Transpose. table = Take[Import["~/myfile.csv"]]; {x, y, z, time, bool} = Transpose[table]; (* do stuff *) output = Transpose[{x, y, z, time, bool}]; Export["newfile.csv", output, "CSV"]


2

If I try to create a CSV file without the first line indicating the seperator, the resulting file is readable by Excel. Export["test2.csv",RandomInteger[{-5,5},{5,3}]] But if you still want the first line, I would do something like this Export["test3.csv", "sep = ,\n" <> ExportString[RandomInteger[{-5, 5}, {5, 3}], "CSV"] , "Text"]


2

It depends on what you want to do with your data afterwards Needs["DifferentialEquations`InterpolatingFunctionAnatomy`"] l = Flatten[ Table[{{x, y}, x^2 + y^2}, {x, -1, 1, .1}, {y, -1, 1, .1}], 1]; f = Interpolation[l]; (* To export as a text file*) ListPlot3D[ r = Flatten /@ Transpose[Flatten[#, 1] & /@ ...


1

A bit more detailed solution for mixed data. First the CSV data is loaded as a list of records by ReadList (like Mr.Wizard's answer) and then the appropriate columns are converted to expressions, except for the first line that is expected to provide the column labels. columnNumber = 8; expressionColumns = {2, 6, 8}; data = ReadList["sample.csv", ...


1

Import["temp.csv","Table"] should do what you want. For my test .csv file I had: 1,0022002,3 0,0003101,0 and the following doesn't strip the leading zeros as desired: Import["temp.csv","Table"] (* {{"1,0022002,3"}, {"0,0003101,0"}} *)


1

Looking at the sample file, it seems that your data may be on a regular grid: data = Import["wafer test 5-8-12 test5.csv"]; data = GatherBy[data, First]; Equal @@ dd[[All, All, 2]] (* ==> True *) which means that we could also use ArrayPlot, if you want a more 'discrete' appearance: ArrayPlot[Transpose[dd[[All, All, 3]]], ColorFunction -> ...



Only top voted, non community-wiki answers of a minimum length are eligible