Create 2d array from csv file in python 3

Daniel Sampras

I have a .csv file which contains data like the following example

A,B,C,D,E,F,
1,-1.978,7.676,7.676,7.676,0,
2,-2.028,6.081,6.081,6.081,1,
3,-1.991,6.142,6.142,6.142,1,
4,-1.990,65.210,65.210,65.210,5,
5,-2.018,8.212,8.212,8.212,5,
6,54.733,32.545,32.545,32.545,6,
..and so on

The format is constant.

I want to load the file in a variable "log" and access them as log[row][column]

example
log[0][2] should give C
log[3][1] should give -1

If use this code

file = open('log.csv')
log = list(file)

when i use this code i get only one dimensional. log[row]

Is their any way to directly store them?

for example

read the file
split with '\n'
split again with ','

Thanks!!

Liberalist D

Try this

log = [line.split(',') for line in open('log.csv')]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Create a dictionary from a csv file in python 3

From Dev

how to create 2d array with 3 elements from 1d array using python

From Dev

Create 3D array from existing 2D array in Python

From Dev

Create a .obj file from 3d array in python

From Dev

How to read csv file into Python 2d array?

From Dev

Create a Random Blank Matrix (2D array) in Python 3?

From Dev

Python array from CSV file

From Dev

Parsing .csv file into 2d array

From Dev

Transfer a 2D array to a csv file?

From Dev

Converting CSV File Into 2D Array

From Dev

Transfer a 2D array to a csv file?

From Dev

Create 3D array from a 2D array by replicating/repeating along the first axis

From Dev

extract data from csv file and put to 2D Array - refactoring

From Dev

How to populate a 2D array with Strings (char*) from a CSV file in C

From Dev

Reading data from a .csv file to append into a 2D array in c

From Dev

Python/Pandas create zip file from csv

From Dev

Python: extract a 2D array from a 3D array

From Dev

python from 2D array to 3D coordinates array

From Dev

Ploting 3D points from csv file, Python?

From Dev

Reading from file into 2D array

From Dev

Python: Create a 3d mask from 2d masks

From Dev

how to create weighted 2D array from networkx object in python

From Dev

Create many csv files from a main csv file with python

From Dev

Python - Create an array from columns in file

From Dev

Read CSV file to a 2D array on C

From Dev

Write a 2d array to a csv file with delimiter

From Dev

Importing a csv file in Matlab with multiple types into a 2D array

From Dev

Convert 2D Array to CSV file in PHP - String Error

From Dev

Generating 3D array from 2D array

Related Related

HotTag

Archive