I want to take the value of column 4 from column 3 (their both integers), this is what I have.
with open('CLASSES.csv', 'rt')as f:
for column in reader:
difference = [x for x in people] - [x for x in people]
Like @Peter Wood said in the comment, you need to subtract inside of one list comprehension, not doing two list comprehension as this results in
list - list.
Also you need to convert to numbers.
difference = [int(x) - int(x) for x in people]
If you want to do stuff like this, you are probably better off using
numpy or even
Using numpy and it's
import numpy as np people = np.genfromtxt('CLASSES.txt', delimiter=',', dtype=None) difference = people[:, 3] - people[:, 4]
people will be a two dimensional numpy array, this first index going over the rows, second over the columns
[:, 3] takes every row of the thirds column.
dtype=None option lets
genfromtxt automatically decide the type for each column, default is