I am getting a name error with the variable data_A and I cannot figure out why...any help appreciated. Thanks! the variable of concern is data_A
import sys import csv import statistics #modularizing week1 program def main(): try: column = int(sys.argv[1]) filename = sys.argv[2] with open(filename,'r') as csv_file: csv_x = csv.reader(csv_file, delimiter=' ', skipinitialspace=True) data_A = [float(line[column-1]) for line in csv_x if (float(line[column-1]))!=-9999.0] except: column = int(sys.argv[1]) csv_x = csv.reader(sys.stdin, delimiter= ' ', skipinitialspace=True) data_A = [float(line[column-1]) for line in csv_x if (float(line[column-1]))!=-9999.0] #statistical analysis for data print( 'min:', min(data_A), 'max:', max(data_A), ', average:', mean(data_A), ', median:', median(data_A) ) def compute_stats(values): import statistics if values == []: return(None,None,None,None) else: minimum = min(values) maximum = max(values) mean = statistics.mean(values) median = statistics.median(values) return(minimum,maximum,mean,median) #call main function if code is not working if __name__ == "__main__": main()
https://stackoverflow.com/questions/67040964/why-am-i-getting-a-nameerror-with-below-code April 11, 2021 at 10:34AM
没有评论:
发表评论