I need to read in a csv file line by line and do some calculations. For example, let's say I have a csv file named test.csv with data below. I want to read the file in line by line and calculate profit for each client(revenue-expenses).
client,revenue,expenses
client_a,1000,450
client_b,2000,1200
client_c,1500,350
I've been looking around a lot online and I'm not exactly sure. I can read the file line by line or print the file, but not sure if I need to assign variables for each field. I assume i need to declare them as int since I am doing calculations.
I don't want to use a list.
Here's what i have to read the file in and print it on the screen. I know I need to loop through the file line by line and do the calculation. Struggling with how to call the values from the csv file and how to ignore the first line.
inputfile = open('test.csv', "r")
print(inputfile.readline())