-1

I'm looking for the max and min value of the variable "Inc", then I need to find the corresponding values of the max and min for "psavings", "savings", and "Con".

import csv
import numpy
psavings = []
savings = []
Con = []
Inc = []
Csv_file = open('/Users/charlesadams/Desktop/Lab.csv')
csv_reader = csv.reader(csv_file, delimiter=",")
next(csv_reader)
for row in csv_reader:
    consumption, income = row
    Con.append(float(consumption))
    Inc.append(float(income))
    savings.append(float(income)-float(consumption))
    psavings.append((float(income)-float(consumption))/ float(income) * 100)

2 Answers2

1
min_inc = min(Inc)
max_inc = max(Inc)
# etc....
Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
0

I'm using this previous answer is a reference: https://stackoverflow.com/a/48519235/3443106

Numpy has a function called where() which returns the location of a value in a numpy array.

So you can do something like this:

x = np.array([1,8,3,4,0,7,2,3,19,11])
y = np.array([2,5,3,4,0,1,0,3,4,9])
y[np.where(x == max(x))]

The output would be array([4]).

Maher Said
  • 170
  • 2
  • 15