In: Computer Science
Given a csv file named “result_niwtawq.csv”, extract the data from it. Store the first column data to a list named time, second column data to a list named Turb_annual_avg, third column data to a list named Turb_min, fourth column data to a list named Turb_max, fifth column data to a list named Turb_mean. Calculate and write the average, maximumand minimumof Turb_min to a file named “lab3_output.txt”.
https://dropbox.cse.sc.edu/pluginfile.php/256369/mod_assign/introattachment/0/result_niwtawq.csv?forcedownload=1
CODE :
# import modules
import pandas as pd
import numpy as np
# read data from csv file to data frame
data = pd.read_csv("result_niwtawq.csv")
# Store the first column data to a list named time
time = data.iloc[:, 0].tolist()
# store second column data to a list named Turb_annual_avg
Turb_annual_avg = data.iloc[:, 1].tolist()
# store third column data to a list named Turb_min
Turb_min = data.iloc[:, 2].tolist()
# store fourth column data to a list named Turb_max
Turb_max = data.iloc[:, 3].tolist()
# store fifth column data to a list named Turb_mean
Turb_mean = data.iloc[:, 4].tolist()
# Calculate and write the average, maximum and minimum of Turb_min
average = np.mean(Turb_min)
maximum = np.max(Turb_min)
minimum = np.min(Turb_min)
# Open lab3_output.txt file
output_file = open("lab3_output.txt", "w")
# Write data to file
output_file.write("{}, {}, {}".format(average, maximum, minimum))
# Close the file
output_file.close()
SCREENSHOT :
