Julio
Julio

Reputation: 21

Pandas how to separate same row with duplicate columns

So, by using pandas.concat with axis=1 I got the following dataframe:

'A' 'B' 'C' 'D' 'E' 'A' 'B' 'C' 'D' 'E'
0 1 2 3 4 5 6 7 8 9 10

But I need the data to be displayed like the folowing example:

'A' 'B' 'C' 'D' 'E'
0 1 2 3 4 5
1 6 7 8 9 10

Is there a way to either transform the first dataframe I talked about in the second one, or get the second one directly with another command other than concat?

Upvotes: 1

Views: 41

Answers (2)

Jahyeon Jee
Jahyeon Jee

Reputation: 1

you should just use df.append() function not, pd.concat().
here is a brief example.

df = pd.DataFrame(columns=['a','b'], data=[[1,2]])
df2 = pd.DataFrame(columns=['a','b'], data=[[3,4]])
df.append(df2)

Upvotes: 0

BENY
BENY

Reputation: 323326

Try with axis=0

out = pd.concat([df1,df2],axis=0)

Upvotes: 1

Related Questions