I have a text-file which has 9 columns and many rows (around 30k). The entries in the first five columns in some of its rows can have same value. In such case I want to convert them into a single row, where the value in the entries of 6th-8th columns would be the mean. If a row is unique then I want to print it as it is. My original file looks like this.
6nbn A 18 49 A 1.82270650408 2.03219831709 1.82706048066 1
6nbn A 45 98 A 1.82498684927 2.03457366541 1.82271363631 1
6nbn A 88 107 A 1.82115046056 2.03480564182 1.82785940378 1
6nbn A 18 49 A 1.81906074665 2.03189099117 1.82705062875 2
6nbn A 45 98 A 1.82562290739 2.03479384705 1.82313137212 2
6nbn A 88 107 A 1.82279510642 2.03515331118 1.82660203657 2
6nbn A 18 49 A 1.82147248126 2.03104332795 1.82474573571 3
6nbn A 45 98 A 1.82470216748 2.03683136268 1.82329893325 3
6nbn A 88 107 A 1.82258525178 2.0307116979 1.8247273769 3
8tfv A 11 18 A 1.81042122171 2.01948136906 1.80238314462 1
8tfv A 11 18 A 1.80688488842 2.02074367499 1.8064168954 2
8tfv A 11 18 A 1.80874790947 2.02178955384 1.80609219034 3
8tfv A 11 18 A 1.80850988385 2.01873277082 1.80290765155 4
8tfv A 11 18 A 1.80312229203 2.01855121312 1.80927195302 5
8t11 B 1 4 A 1.80874790947 2.02178955384 1.80609219034 1
And I want my output file like this:
6nbn A 18 49 A 1.82107991066 2.03171087874 1.82628561504
6nbn A 45 98 A 1.82510397471 2.03539962505 1.82304798056
6nbn A 88 107 A 1.82217693958 2.03355688363 1.82639627242
8tfv A 11 18 A 1.80753723909 2.01985971637 1.80541436699
8t11 B 1 4 A 1.80874790947 2.02178955384 1.80609219034
I am a novice in python programming. I would be a great help if you could help me to solve this problem.