Message Boards Message Boards

0
|
4896 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

[?] Import data from a TSV without degrees?

Posted 6 years ago

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
2 Replies
Posted 6 years 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
Posted 6 years ago

Thanks. That worked.

POSTED BY: Michael Madsen
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract