I have a data frame like this
JavaScript
x
5
1
import pandas as pd
2
import numpy as np
3
df = pd.DataFrame(np.array([[0,2,5,3], [3,1,4,2], [1,3,5,2], [5,1,3,4], [4,2,5,1], [2,3,5,1]]))
4
df
5
Now, I need first row of data frame and make it another data frame
like
JavaScript
1
6
1
row
2
0 0
3
1 2
4
2 5
5
3 3
6
Advertisement
Answer
Use DataFrame.iloc
like:
JavaScript
1
2
1
df1 = df.iloc[0].to_frame('row')
2
For Series
:
JavaScript
1
2
1
s = df.iloc[0]
2