0
votes

I am curious why when I run this, the function "parsenumber" gets outputted as a Seq and not just an int.

|> Seq.map (fun ((number,income,sex,house),data) -> 
    let parsenumber = number |> Seq.skip 9 |> Seq.take 5
    let numberofpets = data |> Seq.map (fun row -> (1.0 - float row.pets))
    ((parsenumber,income,sex,house),numberofpets)

This is the result:

(<seq>, "30050", "Male", "Yes")
(<seq>, "78000", "Female", "No")

How can I change this so it outputs the number and not <seq>.

With Seq.skip and Seq.take, I am trying to skip the first 9 integers of each observation in number and return the last 5.

RAW CSV DATA:

10000000001452,30050,Male,Yes
10000000001455,78000,Female,No

What I want as a result:

('01452','30050','Male','Yes')
('01455','78000','Female','No')

What I am actually getting:

(<seq>, "30050", "Male", "Yes")
(<seq>, "78000", "Female", "No")

I need to not have as an output, and the actual number instead.

1

1 Answers

2
votes

When you say, "I am trying to skip the first 9 integers of each observation in number and return the last 5", did you mean "digits" rather than "integers"? I.e., is number a string originally? Then you should use number.Substring(9, 5) instead of Seq.skip and Seq.take. The Seq.skip and Seq.take functions are defined as returning sequences — that's what they're for. When you interpret a string as a sequence, it returns a sequence of characters. If you use the .Substring method, it returns a string.

BTW, if you want to use .Substring, you'll need to tell F# what type you expect number to be: calling methods of a parameter is one place where F#'s type inference can't figure out what type you have. (Because in theory, you could have defined your own type with a .Substring method and meant to call that type). To explicitly declare the type of the number parameter, you'd use a colon and the type name, so that fun ((number,income,sex,house),data) -> would become fun ((number : string, income, sex, house), data) ->. So your entire Seq.map expression would become:

|> Seq.map (fun ((number : string, income, sex, house), data) -> 
    let parsenumber = number.Substring(9, 5)
    let numberofpets = data |> Seq.map (fun row -> (1.0 - float row.pets))
    ((parsenumber, income, sex, house), numberofpets)

Also, parsenumber isn't a function, so that's not a good name for it. Possibly parsednumber would be better, though if I understood more about what you're trying to do then there's probably an even better suggestion.