Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Reading Data From a CSV or Flat File and Creating a Dataset

mjaynottsmjaynotts Posts: 2Member
Hi, I am creating an application where i want to populate a dataset from a CSV file once i have clicked on a load button and chosen the location of the file!!

For example:

If i have a csv containing n columns and m rows. where the first row of the file contains the column headers.

How do i read it in so i can store it in a dataset. I then want to be able to:

- Display the dataset on a datatable;
- Perform a number of tasks on the data:

i.e. do i=1 to (number of rows);
Column_new=Column1 + Column2;

- output the results (column_new) into a new data table.

Each time a file is read in i want it to be able to hold different numbers of columns and rows!!

I am completely stuck any help would be really appreciated..

mj







Comments

  • Malcolm_McLeanMalcolm_McLean Posts: 253Member ✭✭
    CSV files can be surprisingly tricky to parse, because the loader has got to account for all sorts of errors.

    However there is a loader on my website [link=http://www.personal.leeds.ac.uk/~bgy1mm](here) [/link] in the fuzzy logic trees section. Annoyingly, it needs a slight change because not-a-number is handled differently on different compilers.

    Once you've got the loader, you can create a 2D array by calling malloc() to create double ** pointing to the rows, then malloc() to create a double * for each row. Then you populate the 2D array from the CSV object that the loader created.

    Then you forget about the loader and do all you manipulations of the data.

    Writing a CSV file is much easier than reading one. You simply call printf() in a loop, remembering to terminate the last data item in each rown with a newline instead of a comma.

  • Malcolm_McLeanMalcolm_McLean Posts: 253Member ✭✭
    CSV files can be surprisingly tricky to parse, because the loader has got to account for all sorts of errors.

    However there is a loader on my website [link=http://www.personal.leeds.ac.uk/~bgy1mm](here) [/link] in the fuzzy logic trees section. Annoyingly, it needs a slight change because not-a-number is handled differently on different compilers.

    Once you've got the loader, you can create a 2D array by calling malloc() to create double ** pointing to the rows, then malloc() to create a double * for each row. Then you populate the 2D array from the CSV object that the loader created.

    Then you forget about the loader and do all you manipulations of the data.

    Writing a CSV file is much easier than reading one. You simply call printf() in a loop, remembering to terminate the last data item in each rown with a newline instead of a comma.

Sign In or Register to comment.