Question: I have an `input` file where first column values are same and other column values are different.
i want to sum the values of `third` column only(first row to first row...) and want to keep the added values just beside of common first column values.

input

```
> > > >
1.000 3 0.002
2.010 4 -0.001
3.020 5 -0.001
> > > >
1.000 5 0.003
2.010 6 0.005
3.020 6 0.002

```

expected output

```
1.000 0.005
2.010 0.004
3.020 0.001

```

My script

```
import numpy as np
data=np.load("input.txt", allow_pickle=True)
summ=np.sum(data[:,2])

```

Error: Failed to interpret file 'input' as a pickle. Additionally any numpy based solution will be highly appreciated.Thanks.

Answer: 
Write a Python program to

1. Read the first two lines from a text file named "file1.txt"
2. Write the two lines read from "file1.txt" to a new file called
"file2.txt"
3. Read "file2.txt" and Print the contents

```py
fhandle1 = open("file1.txt","r")
fhandle2 = open("file2.txt","w")

str = fhandle1.readline()
fhandle2.write(str)
str = fhandle1.readline()
fhandle2.write(str)

fhandle1.close()
fhandle2.close()

fhandle3 = open("file2.txt")
print(fhandle3.read())
fhandle3.close()

```
For 2 lines:

```
with open("file1.txt", "r") as r:
    with open("file2.txt", "w") as w:
        w.write(r.readline() + r.readline())

```

Each time `r.readline()` is called, it goes to the next line. So if you wanted to read `n` lines; use:

Note that `.readline() + r.readline()` is only 2 seperate lines if there is a new line (`\n`) at the end of the first line

```
with open("file1.txt", "r") as r:
    with open("file2.txt", "w") as w:
        # Change 2 to number of lines to read
        for i in range(2):
            w.write(r.readline())

```