Question: Please do not copy from the other answer. csv in Java I want to get mean of each columns that I have in csv file,
Please do not copy from the other answer.
csv in Java
I want to get mean of each columns that I have in csv file, but random place has ? in it and the last column contains condition. I want to ignore whenever the scanner finds ? but continues to find the mean of that column. However, I want to find the mean of the column that the condition are the same.
For example, when we look at F1 column 3.0(T), ?(F), 11.0(F), 0(T), ?(T), 4.0,(F), I could be able to find ?(F) by taking mean of (11+4.0)/2 = 7.5 that has the same condition(F) as ?(F).
Also, I could be able to find ?(T) by taking mean of (3.0+0)/2 = 1.5 that has the same conditon as ?(T)
After I get the mean, I want to replace ? with the mean value to the appropriate condition. And produce a new csv file that has the mean value that was replaced for ?
example1.csv
| F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | Condition |
| 3.0 | 2.0 | 12.0 | 3.0 | 4.0 | 5.0 | 9.0 | 9.0 | 2.0 | 9.0 | T |
| ? | 2.0 | 4.0 | 4.0 | 2.0 | 4.0 | 1.0 | 5.0 | 60.0 | ? | F |
| 11.0 | ? | 3.0 | ? | ? | ? | 2.0 | 5.0 | 32.0 | 0 | F |
| 0 | 0 | 2.0 | 4.0 | 11.0 | 5.0 | 4.0 | 6.0 | 7.0 | ? | T |
| ? | 10.0 | ? | 1.0 | ? | 4.0 | ? | 1.0 | ? | 11.0 | T |
| 4.0 | ? | 0 | 3.0 | 5.0 | 3.0 | 1.0 | 3.0 | ? | 4.0 | F |
example2.csv with mean implemented where the condition are the same
| F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | Condition |
| 3.0 | 2.0 | 12.0 | 3.0 | 4.0 | 5.0 | 9.0 | 9.0 | 2.0 | 9.0 | T |
| 7.5 | 2.0 | 4.0 | 4.0 | 2.0 | 4.0 | 1.0 | 5.0 | 60.0 | 2.0 | F |
| 11.0 | 2.0 | 3.0 | 3.5 | 3.5 | 3.5 | 2.0 | 5.0 | 32.0 | 0 | F |
| 0 | 0 | 2.0 | 4.0 | 11.0 | 5.0 | 4.0 | 6.0 | 7.0 | 10.0 | T |
| 1.5 | 10.0 | 6.0 | 1.0 | 7.5 | 4.0 | 6.5 | 1.0 | 4.5 | 11.0 | T |
| 4.0 | 2.0 | 0 | 3.0 | 5.0 | 3.0 | 1.0 | 3.0 | 46.0 | 4.0 | F |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
