# Issue

I was wondering how I can append a selected part of a matrix to a matrix in python? The link below shows the excel file data that I am using and am trying to append with:

My current program is shown below:

```
import pandas as pd
main=pd.read_csv('C:/Users/Jonas/Desktop/testfile/testing.csv', header=None)
main_transposed=main.T
#Next excel file
wave_file=pd.read_csv('C:/Users/Jonas/Desktop/testfile/nxt_Test.csv', header=None)
wave_transposed=wave_file.T
```

Thanks

# Solution

Firstly, the best for matrix problems is the Numpy library, so convert your DataFrame to ndarray (simply) then use the bellow concept of collecting parts of the matrix:

```
import numpy as np
a=np.array([[1,2,3],[4,5,6],[7,8,9]])
b=np.array([[10,12,11],[100,5,79]])
b1_above_a=np.reshape(np.append(b[1,:],a),(4,3))
a_above_b1=np.reshape(np.append(a,b[1,:]),(4,3))
```

Now the b1_above_a is the second row of b put above matrix a, and the reverse with a_above_b1, that we put the whole matrix a above the second row of b. Now keep in mind the output will be flattened so reshape it.

Answered By - Hasanen A. Sahib Answer Checked By - Terry (PHPFixing Volunteer)

## 0 Comments:

## Post a Comment

Note: Only a member of this blog may post a comment.