Assuming that you have a CSV file and would like to treat it as an array:

You could use genfromtxt from the numpy module, this will make a numpy array with as many rows and columns as are in your file ( X in code below).Assuming the data is all numerical you can use savetxt to store values in the csv file:

import numpy as np X = np.genfromtxt("yourcsvfile.dat",delimiter=",") X[0,0] = 42 # do something with the array np.savetxt('yourcsvfile.dat',X,delimiter=",")

EDIT:

If there are strings in the file you can do this:

# read in X = np.genfromtxt("yourcsvfile.dat",delimiter=",",dtype=None) # write out with open('yourcsvfile.dat','w') as f: for el in X[()]: f.write(str(el)+' ')

Some other techniques in answers here:

numpy save an array of different types to a text file

How do I import data with different types from file into a Python Numpy array?