New answers tagged

2

This ListA = { {{n1, p1, a1}, {n1, p2, a2}, {n1, p3, a3}, {n1, p4, a4}}, {{n2, p1, b1}, {n2, p2, b2}, {n2, p3, b3}, {n2, p4, b4}}, {{n3, p1, c1}, {n3, p2, c2}, {n3, p3, c3}, {n3, p4, c4}}}; Export["MathematicaData.CSV", Transpose[Map[Last, ListA, {2}]]] gives this a1,b1,c1,f1 a2,b2,c2,f2 a3,b3,c3,f3 a4,b4,c4,f4 in your csv file. Note you are ...


2

Update Export["filename.csv", ArrayFlatten[{{0, {list[[1, All, 2]]}}, {List /@ list[[All, 1, 1]], list[[All, All, 3]]}}]] OP I'm assuming all the ns and ps are integers. In that case, do Export["filename.csv", SparseArray[{#1, #2} -> #3 & @@@ Flatten[list, 1]]] This works for the ns and ps in any order. If they are actually in the correct ...


0

I can propose a more general solution. It is based on regular expressions (or here, string patterns). The idea is to look for the shortest strings in the file that begins with double-quote, ends with double quotes, does not contain any double quote, but can contain one or many EndOfLine. As it is a CSV, there are comma before the double-quote (thus, this ...


1

What follows is a variation on a previous answer To exclude row 4 from comma-delimited data: dataGood = Flatten[#, 1] & @(Import["/path/to/myfile.txt",{"Data", #, {All}}] & /@ {Range[3], Range[5, 6]}); and dataGood // TableForm For comparison: dataAll = Import["/path/to/myfile.txt", {"Data", {All}, {All}}]; dataAll // TableForm ...


3

As mentioned in the comments to your question, you just Import the whole data and then manipulate it afterwards. This is (I believe) a very transparent way to achieve the end result that you want and also illustrates why you should not use an "advanced" Import: Let's produce some sample data dim = 100; data = RandomReal[{-1, 1}, {dim, 3}]; ...



Top 50 recent answers are included