Tag Info

New answers tagged

4

This is an unfortunate oversight on the part of Wolfram and would be of general interest, so I wrote a LibraryFunction in C (compiled using CreateLibrary) that will decompress data compressed using the Unix compress command (i.e. .Z files). Here it is: Needs["CCompilerDriver`"] unlzw$source=" /* unlzw version 1.1, 1 October 2014 Copyright (C) 2014 ...


0

You can use the various FileName functions to get the result you want. The following function will import all the files in the folder ../images, modifies them with the function DoThings and exports them with the original file name extended by the last character of the file name. SetDirectory[".../images"]; Export[FileBaseName[#] <> ...


1

If you are looking for a function which takes in a filepath and generates a filepath to a file with nearly the same name, but with a duplication of the final digit of the base name, then you can use String pattern recognition like this: formatString = First@StringCases[#, x__ ~~ y_ ~~ ".jpg" :> x <> y <> y <> ".jpg"] &; ...


2

Just an alternative: f = Import["my_file.pdf", "Pages"]; MapIndexed[Export["page"<>IntegerString[First@#2,10,2]<>".png",#1]&,f] The use ofIntegerString allows left padding with zero which may useful in ordering files. In this case 2 -> 01,02,..99. This could be modified for large number.


3

Is there a way to convert the PDF pages into images within Mathematica Yes, just do f = Import["my_file.pdf", "Pages"]; and now f is a list, each is one page. Then use Export["f.png",f[[1]]] to export the first page as png Here is MWE SetDirectory[NotebookDirectory[]]; f = Import["my_file.pdf", "Pages"]; Export["page" <> ToString[#] <> ...


5

Classify actually supports a nice syntax for this: Classify[<|"class1" -> Import["class1/*"], "class2" -> Import["class2/*"]|>]


1

Depending which kind of processing you need, you can try to digest the information as you read, line by line. I wrote this to answer another question about sorting long files. Its based on OpenRead and Read. In this case it reads one line, stores only one number from the file and the StreamPosition in a table for indexing. strR = OpenRead["UnSorted.txt"] ...


7

For the first case, one way will be to read the entire file as a String and manipulate it e.g: txt = ReadList["dose.txt", String]; Then do something like: Flatten @ StringCases[txt, "Mean Dose [%]: " ~~ (x : NumberString) -> ToExpression @ x] {103.3} I guess you can turn it into a function: sValues[s_String] := Flatten @ StringCases[txt, s ~~ ...


2

Assuming the XLS file is in this URL: url = "http://statlinks.oecdcode.org/982013061P1T001.XLS"; This gives you the list of sheets in the XLS file sheetslist = Import[url, {"XLS", "Sheets"}]; And you can Import the second sheet by Import[url, {"Sheets", sheetslist[[2]]}] Backtracking, now to get that URL... Get a list of links in the page: ...


4

I don't think SemanticImport has been designed to deal with multiple Excel sheets. I work around this problem using Import to get the number of sheets and their names, and to import them and ExportString to export them as "TSV" which, on its turn, can be imported by SemanticImportString. An intermediate conversion of DateObject/TimeObject to DateString is ...


1

sheets = Import["sample.xlsx", "Sheets"] (*{"DataSet1", "DataSet2"}*) data = Import["sample.xlsx", "Data"] (*{{{"Country", "Value"}, {"AR", 10.}, {"BE", 20.}, {"SG", 30.}, {"TW", 40.}}, {{"City", "Value", "Color"}, {"Amsterdam", 10., "Blue"}, {"London", 20., "Red"}, {"Paris", 30., "Yellow"}}}*) Set[Evaluate[Symbol[#] & /@ sheets], data]; ...


2

Even though I don't see it in the documentation, you can use All when specifying what elements you want to import. So for an example Excel spreadsheet: We can import the 2nd and 5th elements from every row on the first sheet as such: Import["pathtoxlsx.xlsx", {"Data", 1, All, {2, 5}}] {{0.612328, 0.325049}, {0.909502, 0.206016}, {0.531286, ...


8

Using SemanticImport["testdata.csv"] I get on the exported data you provided which is the dataset you seek. But SemanticImport has been reported to have a few bugs, maybe that's why you can't get it to work. In the meantime, and in between time, you can use the much cleaner approach to obtain your dataset after using Import on your file: data = ...


2

Your file seems to be corrupt, there is one extra byte in the header section. Open in a binary clean text editor, search for "uK^2" and delete exactly one space following the 2. The file can then be read by this: (adapted from link in comment) f = OpenRead["test.fits", BinaryFormat -> True]; parsehead[hh_] := (metadat[#[[1]]] = #[[2]]; #) & ...


0

Below I give some code for cvt that converts a number string to a number with the same accuracy as the string. Example: datastring = "8.2457409790900005e+08\n8.2457409810599995e+08"; StringCases[datastring, s : floatpat :> cvt[StringSplit[s, "e" | "E"]]] (* {8.2457409790900005*10^8, 8.2457409810599995*10^8} *) Some slight variations: ...


0

Note that the trick of adding a zero only works for numbers in scientific notation: This is a convoluted approach that works with arbitrary floats: toarbprecision[string_] := Module[{dp, ep, firstnonzero, mend, pow, dig}, dp = StringPosition[string, "."][[1, 1]]; ep = StringPosition[string, "e" | "E"]; firstnonzero = ...



Top 50 recent answers are included