Skip to content
Advertisement

Loading data from a file and converting into an array in Python

I am trying to load the data from a file. There are 3 rows and columns and I want to convert into an array A with shape (3,3). How do I go about doing it?

JavaScript

The data looks like

Data

The array A should be

JavaScript

Advertisement

Answer

Following my comment, convert the file to a panda dataframe first to get rid of the empty rows in your dataset. Then convert the resulting dataframe to numpy.

data.csv

JavaScript

code

JavaScript

output

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement