I have dataframe df:
JavaScript
x
7
1
0
2
0 a
3
1 b
4
2 c
5
3 d
6
4 e
7
O/P should be:
JavaScript
1
8
1
a b c d e
2
0
3
1
4
2
5
3
6
4
7
5
8
I want column containing(a, b,c,d,e) as header of my dataframe.
Could anyone help?
Advertisement
Answer
If your dataframe is pandas and its name is df. Try solving it with pandas:
Firstly convert initial df content to a list, afterwards create a new dataframe defining its columns with the list.
JavaScript
1
5
1
import pandas as pd
2
3
list = df[0].tolist() #df[0] is getting the content of first column
4
dfSolved = pd.DataFrame([], columns = list)
5