MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Importing data with comma as decimal separator

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98148] Re: Importing data with comma as decimal separator
  • From: annetts729 <davidannetts at aapt.net.au>
  • Date: Tue, 31 Mar 2009 04:20:08 -0500 (EST)
  • References: <gqq3sb$7mt$1@smc.vnet.net>

Hi Dom,

> I would like to import two-column numerical data in which comma is
> used as decimal separator. The first 12 lines of the file is header,
> followed by two tab-separated columns of numbers.
> How I can do this in Mathematica 6.0?
> Thanks.

You can use Import.  Something like the following sequence might work
for you.

idata = Import["Test.txt", "Table"]; (* import all the data as strings
-- the default for *.txt *)
sdata = Select[idata, UnsameQ[#[[1]], "#"] &] (* drop all header
lines  -- sdata = Drop[idata, {1, 12}] can also work *)
ddata = StringReplace[#, {"," -> "."}] & /@ sdata (* replace our
commas with decimal points *)
ddata = Map[ToExpression, ddata] (* ... and convert everything to
expressions -- reals *)

Regards,

Dave.




  • Prev by Date: Re: pdf export problem
  • Next by Date: Re: Exporting a discrete Manipulate[] sequence?
  • Previous by thread: Re: Importing data with comma as decimal separator
  • Next by thread: Re: Importing data with comma as decimal separator