Group Abstract Group Abstract

Message Boards Message Boards

1
|
4.9K Views
|
6 Replies
|
1 Total Like
View groups...
Share
Share this post:

The expression does not show any numerical value

Posted 4 years ago

Hello,

I am a noob in mathematica and I do not understand what I did wrong here. The expression I used for N[Last@#/First@#*100] or N[(Last@# - First@#)/First@#] does not display any numerical value, but just the expression with numbers. Can someone maybe help me?

Very thankful already

Attachment

Attachments:
POSTED BY: William Gerisch
6 Replies

Welcome to Wolfram Community! Please make sure you know the rules: https://wolfr.am/READ-1ST

The rules explain how to format your code properly. Images don't help other members to copy your code. Please EDIT your post and make sure code blocks start on a new paragraph and look framed and colored like this.

int = Integrate[1/(x^3 - 1), x];
Map[Framed, int, Infinity]

You can also embed notebook or attach notebook.

enter image description here

POSTED BY: EDITORIAL BOARD
Posted 4 years ago

They are probably just strings in your input file. If you don't control the input file, you'll just have to fix them up on import. When I deal with data normalization, I'll have a "parse" function where I put the knowledge about formats, like which fields are strings and need to be numbers. I'd probably write something like this, that handles a single record:

parseEconomicData[{date_, rest__}] := 
    Prepend[Map[parseNumericText, {rest}], date]

parseNumericText[""] := 0 (* what to fill in for empty fields *)
(* add other definitions to match other patterns you want to handle separately *)
parseNumericText[n_String] := Interpreter["Number"][n]

Then with this, if I'm reading your code rightly, I'd make SP500 this way (First on ecodata because it has an extra outer layer, then Rest to skip the header row; I wasn't sure the last number on your Range is a magic number that cuts off something from the end, or if it was just meant to go to the end; note you can use -1 to indicate the last entry):

SP500 = parseEconomicData[Rest[First[ecodata]]]

This is just one way to structure the code. I find it helpful to split things up logically like this with nice names, comments etc. to help me think clearly about the problem and decompose it into nice separable, logical, testable chunks. If something turns out to be especially slow using this approach I can always go back and optimize.

POSTED BY: Joel Klein

Hey again, thanks for your recommendation. It actually works now and I changed the strings into numbers. You were a great help!! Thank you so much :)

POSTED BY: William Gerisch
Posted 4 years ago

Oh, good :)

I have to do some similar things, data science-y for work and financial stuff for my own needs so this is a familiar pattern.

POSTED BY: Joel Klein
Posted 4 years ago

You don't show how you got your input to this, but if I had to guess, you have some strings that have numeric representations mixed in with numbers.

Try wrapping your final output with InputForm, which will show the string quotation marks if they are there, and that should help backtrack to where they need to be parsed via something like Interpreter["Number"].

For example:

InputForm[seven]

Good luck!

POSTED BY: Joel Klein

Hello Joel,

thanks for your help! They are indeed strings. I added my code, because I do not really understand why they are strings in the first place. I am very new to this so sorry for the questions.

Attachment

Attachment

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