Message Boards Message Boards

[✓] Import data from a TSV without degrees?

GROUPS:

I'm a hobbyist and dabble in a few things. This is my first post. I have a .TSV that I exported from DataDrop that has a timestamp and a temperature in Degrees Fahrenheit. I'm able to get it to import using a variety of methods. However, the result of hwtemp is showing as # [Degree]F.

How can I just get the number?

hwd = Import[   "hw.tsv", {"Data", All, 1}];
hwtemp = Import["hw.tsv", {"Data", All, 2}];

date = DateObject[Rest[hwd]];
temperature = Rest[hwtemp] // Short

Any help or feedback is welcome.

Thanks, Mike

Attachments:
POSTED BY: Michael Madsen
Answer
4 months ago

Hi Mike, You could use StringReplace to delete all the characters including and after the space of the result like this:

hwd = Import["~/Desktop/hw.tsv", {"Data", All, 1}]; 
hwtemp = Import["~/Desktop/hw.tsv", {"Data", All, 2}];
date = DateObject[Rest[hwd]];
temperature = Rest[hwtemp];
temps = StringReplace[temperature, " " ~~ __ -> ""]

If you want to turn these temps into Integers, simply map ToExpression to interpret the number string as an Integer:

ToExpression /@ temps

If you need Real values rather than Integers, this would do the trick:

temps = ToExpression /@ StringReplace[temperature, " " ~~ __ -> "."]
POSTED BY: Sean Cheren
Answer
4 months ago

Thanks. That worked.

POSTED BY: Michael Madsen
Answer
4 months ago

Group Abstract Group Abstract