More Clarification | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

More Clarification

I have tow data.csv in array I wanna use them in my code in the same time and print mean and median from them what I should to do (by function)

11th Apr 2020, 4:35 PM
Abubakar Mastour Adam Fadul
Abubakar Mastour Adam Fadul - avatar
4 Answers
+ 4
Are you trying to use the tow data.csv as a module? I mean, like I importing it into your main code?
11th Apr 2020, 4:40 PM
Mujeeb Adeyanju Sunmola
Mujeeb Adeyanju Sunmola - avatar
+ 1
Not sure what you mean tow data csv (unless it's a typo and it should read "two data csv array"). ...anyway......Have a look at the statistics module for the mean and median functions.
11th Apr 2020, 4:58 PM
rodwynnejones
rodwynnejones - avatar
+ 1
Not sure if this is what you need but:- just to add...I've heard of numpy but never used it. def calc_stats(dataA, dataB): meanA = np.mean(dataA) medianA = np.median(dataA) meanB = np.mean(dataB) medianB = np.median(dataB) return #do what you need to return here # data1 = np.array("data.csv", delimiter =',') data2 = np.array("data2.csv", demiliter=',') print(calc_stats(data1, data2))
11th Apr 2020, 5:40 PM
rodwynnejones
rodwynnejones - avatar
0
Ok guys I wrote it like this import numpy as np def calc_stats(data): data = np.array("data.csv", demiliter=','): mean = np.mean(data) median = np.median(data) return np.round(mean, 1), np.round(median, 1) if __name__ == "__main__": print(calc_stats(np.mean)) And the code work with me without any problem But I have another data (data2.csv) i wanna use both of them in the above code and I wrote it like this data = np.array("data.csv, data2.csv, delimiter =','): And when I printed appear to that there are some thing wrong Just I need help how to add my second data to same code
11th Apr 2020, 5:16 PM
Abubakar Mastour Adam Fadul
Abubakar Mastour Adam Fadul - avatar