Message Boards Message Boards


[✓] Import data from a TSV without degrees?

Posted 9 months ago
2 Replies
2 Total Likes

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

2 Replies
Posted 9 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 9 months ago

Thanks. That worked.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract