Skip to content
Fix Code Error

How do I read CSV data into a record array in NumPy?

March 13, 2021 by Code Error
Posted By: Anonymous

I wonder if there is a direct way to import the contents of a CSV file into a record array, much in the way that R’s read.table(), read.delim(), and read.csv() family imports data to R’s data frame?

Or is the best way to use csv.reader() and then apply something like numpy.core.records.fromrecords()?

Solution

You can use Numpy’s genfromtxt() method to do so, by setting the delimiter kwarg to a comma.

from numpy import genfromtxt
my_data = genfromtxt('my_file.csv', delimiter=',')

More information on the function can be found at its respective documentation.

Answered By: Anonymous

Related Articles

  • Upload a file using vuejs and laravel without a form
  • Join list of lists into a delimiter separated list of lists
  • How to add column to numpy array
  • Reimplementing html table with polymer not work
  • Cannot find control with name: formControlName in angular…
  • Eclipse will not start and I haven't changed anything
  • pthreads again: why does the for-loop inside my thread…
  • Using enums in a spring entity
  • Polymer core-scaffold element not showing inside core-pages
  • data.table vs dplyr: can one do something well the other…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Scroll Automatically to the Bottom of the Page

Next Post:

Fetch: POST json data

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Get code errors & solutions at akashmittal.com
© 2022 Fix Code Error