Dante Smith
Dante Smith

Reputation: 581

Pandas Place Columns Data into Rows of Existing

I have a dataframe as seen below and am trying to place the existing information to other columns.

A   B   C
aa   bb  cc  dd  ee  ff gg hh ii .....

and I am trying to get the other columns of information to go under columns A-C.

A   B   C
aa  bb  cc  
dd  ee  ff 
gg  hh  ii 

Any idea of how to do so? Thanks for your help!

Upvotes: 0

Views: 17

Answers (1)

Quang Hoang
Quang Hoang

Reputation: 150785

If the number of columns is divisible by 3, you can use reshape:

pd.DataFrame(df.values.reshape(-1,3), columns=['a','b','c'])

Upvotes: 1

Related Questions