I have a python class that read a CSV file and populate the information into separate field in the class.
class DataCSVReader(object):
def __init__(self):
self.data_name1 = []
self.data_name2 = []
....
self.data_nameN = []
def read_from_csv(self, filename):
data = np.genfromtxt(filename, delimiter=',', skip_header=1)
self.data_name1 = data[:, 1:4]
self.data_name2 = data[:, 4:8]
...
self.data_nameN = data[:, 4*(N-1):4*N]
The file will work and read the data with no problem. But my number of data field N is rather large therefore my code is very long with not much going on. So my questions are:
- Is there a better way to populate the data?
- Is there a better way to write the init so that it can elegantly creating a lot of empty lists?