Hi, I am trying to import a CSV file then find the product of all of the numbers within the file.
So far I have:
import csv
data = list(csv.reader(open(DATA+'mydata.csv','rb'),dialect='excel'))
from numpy import prod
prod(data)
This doesn't
1 | initial version |
Hi, I am trying to import a CSV file then find the product of all of the numbers within the file.
So far I have:
import csv
data = list(csv.reader(open(DATA+'mydata.csv','rb'),dialect='excel'))
from numpy import prod
prod(data)
This doesn't
2 | No.2 Revision |
Hi, I am trying to import a CSV file then find the product of all of the numbers within the file.
So far I have:
import csv
data = list(csv.reader(open(DATA+'mydata.csv','rb'),dialect='excel'))
from numpy import prod
prod(data)
This doesn't work. I think this is because of the format of how the list is created. This list data comes out in this format:
[['1'],['2'],['3']]
How do I coerce it into the format (1,2,3)?
3 | Improved formatting and clarity |
Hi, I am trying to import a CSV file then find the product of all of the numbers within the file.file. The code I have used so far is:
import csv
mylist = list(csv.reader(open(DATA+'mydata.csv','rb'),dialect='excel'))
from numpy import prod
prod(mylist)
However, this doesn't work, I receive the following error "TypeError: cannot perform reduce with flexible type".
So far I have:
import csv
data = list(csv.reader(open(DATA+'mydata.csv','rb'),dialect='excel'))
from numpy import prod
prod(data)
This doesn't work. I think this is because of the format of how the list mylist is created. This list data comes out in this format:
[['1'],['2'],['3']]
[['1'],['2'],['3']]
How do I coerce it into the format (1,2,3)?