aakash T.C.
aakash T.C.

Reputation: 33

If dataframe length exceeds threshold, make a new row python

I have a data frame with columns a,b,c,d

a b c d
1 2 nan nan
2 3 4 5 
4 5 nan nan

how do i reshape into 2 columns, when i am not aware of the number of rows that the result will give. (big data)

output:

a b 
1 2 
2 3
4 5
4 5

Upvotes: 1

Views: 115

Answers (1)

piRSquared
piRSquared

Reputation: 294328

Numpy's reshape

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

     a    b
0  1.0  2.0
2  2.0  3.0
3  4.0  5.0
4  4.0  5.0

Upvotes: 5

Related Questions