Tag Info

New answers tagged

2

You have trailing commas on each line that are imported as empty strings. imported = Import["csv.txt", "CSV", HeaderLines -> 2] {{700.0443115, 0.08416349441, ""}, {699.0369263, 0.08557280153, ""}, {698.0291138, 0.08568932861, ""}, {697.0210571, 0.08601997793, ""}, {696.0126343, 0.08787558973, ""}, {695.0039063, 0.08656696975, ""}, {693.994812, ...


0

It seems there is no ready way to read in this mixed type data. I used the following script to do it, can you take a look to help improve it? The code itself has been tested working, but not quite in the flow of mathematica. f = OpenRead["D:\Code_Develop\data_mathematica.cvs"]; cc = ReadList[f, String]; data1 = StringSplit[cc, ","]; ccm = data1; nn = ...


2

Played around a bit and got to a point where I think I can let you finish it off (and make it more "automatic" and syntactically pleasing). file = "/path/to/file/JCO1DADAP_0000" For an unformatted Fortran 77 file I usually start by opening the stream an looking at the first "Integer32". This will determine how many bytes the record uses. str = ...


2

OP's stuff: html = "<div style=\"text-align: center;\"> This is <span style=\"font-size: 21px;\"> <i>an example</i></span> of a <u> <font face=\"Georgia\" style=\"font-size: 19px;\">text \ cell</font></u> with <font color=\"#c14dff\" style=\"\">complex styles</font> \ ...


0

OK, I found a simple solution, at least if grep or the like is available. Here are the timing results when I apply to the file I used in my original post: rows = ReadList["!grep -iv nan " <> pathToTSV, types, RecordSeparators -> {tab, nl}] // printTime; 3.72033 s ReadList[!grep -v nan <> pathToTSV, types, RecordSeparators -> ...


1

You need to flatten the list and convert elements to numeric values: prob = Import["/home/Desktop/test1.txt", "Table"]// ToExpression// Flatten; Then you can find the Shannon Entropy (without a do loop and initialization): alpha = 1.1; t = Length[prob]; shannon = Sum[-prob[[i]]*Log[prob[[i]]], {i, 1, t}]; Print[{alpha, shannon}] (* ...


1

I would do this line by line, using the ability of ReadList to read a single record via its third argument. You can then check whether you want to keep that record, and Sow it if you do. Thus, I would use something like this: importFunction[path_, columns_, maxRows_:∞] := Block[ {inputstream, record, i = 1}, inputstream = OpenRead[path]; Reap[ ...


2

There is a stray quote on the second line, in YNL039W|B"|TFC5|TFC7|TFIIIB90 the effect of which can be seen here (test.txt is your input) In[1]:= test=Import["~/Desktop/test.txt","TSV","Numeric"->False]; In[2]:= Length/@test Out[2]= {17,7} In[3]:= test//Last//TableForm Out[3]//TableForm= SGD S000004984 BDP1 GO:0000126 ...


1

Code outline: ClearAll[XMLNote]; (*modified, only act on target tags*) XMLNote[ XMLElement[tag : "section" | "TextHeading", attributes_, data_], m_Integer ] := ... (*new, for other tags pass down XML elements*) XMLNote[XMLElement[_, attributes_, data : {__XMLElement}], m_Integer] := Sequence @@ (XMLNote[#1, m + 30] &) /@ data; ...


2

If your data is or can be coerced into a rectangular array of machine Integer, Real, or Complex numbers (all the same type), then you can use ToPackedArray to reduce the amount of memory required, as well as make operations on the data faster. One might have hoped that Import would do this automatically, but it doesn't. You can use ByteCount to see how ...


1

If you look at the InputForm of the List you get from Import, you will notice that all those "empty" entries are actually an empty string, i.e. "". You can then replace the string with an empty Sequence[], and the empty sequence will automatically be flattened out of the list. I generated a .CSV file with your pattern of pairs of columns of different ...


3

I used the answer above to create a small function to grab a bit of sound using the default microphone on my computer. Clear[recordTime]; recordTime[t_: 1] := Module[{device = FrontEndExecute[FrontEnd`RecordSound[5]]}, FrontEndExecute[FrontEnd`RecordSound[1, Keys[First[device]], 1]]; Pause[t]; FrontEndExecute[FrontEnd`RecordSound[2]]; ...


0

my stab at it.. source = Import[ "http://en.wikipedia.org/wiki/List_of_missions_to_the_Moon", {"HTML", "Source"}]; tstart = StringPosition[source, "<table class=\"wikitable sortable\"" ][[1, 1]]; tend = Select[ StringPosition[source, "</table>"] , #[[1]] > tstart & ][[1, 2]]; tabledata = ...


0

As george2079 said, you can use Import: text=Import["https://en.wikipedia.org/wiki/List_of_missions_to_the_Moon", "Data"]; and then naively because table has 7 columns: table=Cases[tmp,{_, _, _,_, _, _, _}, \[Infinity]]; But you need to do some clean-up afterwards!


2

It seems that in version 10 of Mathematica (see Documentation Center), the importation of compound .h5 data is now supported, e.g. : Import["ExampleData/image.h5", {"Datasets", "/image24bitpixel"}]


3

Have a look at the documentation for CSV. The first issue you have is that your file extension is .txt so Mma imports it as text file instead of a CSV file. Your second issue is that "Table" is not a supported element for either CSV or TXT so I think it is just being ignored. Even though your file does not have the .csv file type you can still tell Mma ...


3

imp = Import["file.csv"] (* fake data *) scores = imp[[Join @@ Range[{5, 6}, Length@imp, 12], {3, 7}]]; MFscores = GatherBy[scores, First] {{{"Cayuga ISD", 494}, {"Cayuga ISD", 489}}, {{"Elkhart ISD", 513}, {"Elkhart ISD", 455}}, {{"Westwood ISD", 519}, {"Westwood ISD", 451}}, {{"LaPoynor ISD", ""}, {"LaPoynor ISD", 451}}} You ...


4

Import the data and chose the columns that contain relevant information: In: data = Import["file.csv"]〚All, {1, 3, 7}〛 Out: {{"Female", "A", 1}, {"x", "A", 2}, {"Male", "A", 3}, {"y", "B", 4}, {"Female", "B", 5}, {"Male", "B", 6}, {"Female","C",7}, {"Male", "C", Null}} Select those entries that start with "Female" or "Male" and wich also have a ...


0

Just for completeness the syntax to "directly" import specified rows/columns is like this: Import[ "test.xls", {"Data", 1, {2, 25, 71}, {32, 44}}] which says take sheet 1 , rows 2,25&71 and columns 32,44. For comparison this expression produces the same result by importing everything and extracting the desired parts: Import["test.xls"][[1, {2, ...


2

With a sheet containing Group Distric DistName Cityname regname region Math Critrd All Students 1. s w g 1. 451. x female 5 n t e 7 12. x male 2. r y k 4. 5. x All Students 7. g m m 9. 456. x and the spreadsheet file named Book.xlsx and in a place where Mathematica can find it then this data = First[Import["Book.xlsx"]]; Cases[data, ...


1

Here is an Excel VBA function that will generate the list in an excel cell. Copy the cell and paste directly into mma: Function ToMathematicaList(Y_Values, X_Values) N1 = Y_Values.Count stout = "{" For J = 1 To (N1 - 1) stout = stout & "{" & X_Values(J) & ", " & Y_Values(J) & "}," Next J stout = stout & "{" & X_Values(N1) ...


2

As @george2079 has already pointed out, you are causing confusion in the Import and Export formats by adding the "Table" option. Try the following instead: tableT = Parallelize[ Table[{x, y, func[x, y]}, {x, -5, 5, 1}, {y, -5, 5, 1}] ]; Export["table.xls", tableT]; sampleTable = Import["table.xls"][[1]]; TableForm@sampleTable (* -5. -5. func[-5, ...


1

See if this helps you get started data = First[Import["x21432.mat"]] /. {{x_Real}}->x; Dimensions[data] channels = {"RF", "MH", "LH", "VL", "AT", "MH"}; Table[ ListLinePlot[Rest[data [[All, column]]], AspectRatio->0.2, PlotRange->All, PlotLabel->channels[[column]]], {column, 1, Length[data[[1]]]} ] The First in the first line gets rid of ...



Top 50 recent answers are included