Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8719671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:51:19+00:00 2026-06-13T06:51:19+00:00

How can I access the entries in a csv file in order to perform

  • 0

How can I access the entries in a csv file in order to perform calculations on them in F#?

I can read the csv file into memory in the usual way, but once there I am stuck.

Ideally I would just create arrays from the columns and then use array.map2 to perform calculations.

So I array 1 is some website usage metric, and column 2 is the number of users that reached the value in column 1 (say made 6 visits to a website) we could calculate the mean number of visits by multiplying each entry in an array of column 1, by an array made from column 2 and dividing by the array.sum of column 2.

I have tried the csv to Array code on F# snippets, http://fssnip.net/3T, but it produces and array for me that is a series of string tuples.

Can anyone suggest a better approach?

EDIT: Some sample input would be similar to this:-

     Visits Count
     1  8
     2  9
     3  5
     4  3
     5  2
     6  1
     7  1
    10  1

And the output would be to return the mean of the data, in this case 2.87 (to 2 decimal places).

EDIT 2: The current output from the CSV to array code I found is this

     val it : seq<BookWindow> =
            seq [{Visits = 1;
                  Count = 8;}; {Visits = 2;
                           Count = 9;}; {Visits = 3;
                                  Count = 5;}; {Visits = 4;
                                              Count = 3;}; ...]

which is not so useful for calculations…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:51:20+00:00Added an answer on June 13, 2026 at 6:51 am

    What I do is create a record type so I can use strongly typed operations lateron, and then read the textfile into a seq<myRecord> very quickly like this code below. If i intend to reuse this lateron I usually move the method to the record as static member fromFile. The seq is very useful if you work with large textfiles as I do usually, it uses very little memory this way.

    edit this is cleaner:

    open System.IO
    
    type myRecord = { 
        Visits: int
        Count: int 
    } with
        static member fromFile file = 
            file
            |> File.ReadLines       // expose as seq<string>
            |> Seq.skip 1           // skip headers
            |> Seq.map (fun s-> s.Split '\t') // split each line into array
            |> Seq.map (fun a -> {Visits=int a.[0]; Count=int a.[1]}) // and create record
    
    myRecord.fromFile @"D:\data.csv"
    |> Seq.fold (fun (tv, tc) r -> (tv+r.Visits*r.Count, tc+r.Count))(0,0)
    |> (fun t -> float (fst t) / float (snd t))
    //val mean : float = 2.866666667
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I programmatically access the file allocation entries (FAT) in Windows? I have
I can access and show self.view and see the frame in the log but
We can access the valueStack (and other objects of ActionContext ) using OGNL but
Why I can access Session object in Page_Load method in instance of System.Web.UI.Page, but
I have the following project-tree: I can access the 290.gif file in the path:
Hey guys I have enabled APC on my VPS but now I can't access
I have to create a tlb file so I can access a Python COM
I can access the tags associated with a particular photo via the Graph API,
I can access Spring beans in my Servlets using WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); in
How can hibernate can access a private field/method of a java class , for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.