Created
September 22, 2012 18:43
-
-
Save dettmering/3767366 to your computer and use it in GitHub Desktop.
Python: Read CSV file into array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def readcsv(filename): | |
ifile = open(filename, "rU") | |
reader = csv.reader(ifile, delimiter=";") | |
rownum = 0 | |
a = [] | |
for row in reader: | |
a.append (row) | |
rownum += 1 | |
ifile.close() | |
return a |
This reads each row as a string.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think a better way would be to use Pandas using the following function:
def readcsv(filename):
data = pd.read_csv(filename)
#Please add four spaces here before this linereturn(np.array(data))
#Please add four spaces here before this lineyourArray = readcsv(yourFilename)
Good Luck!