1

I have a large dataframe with multiple columns (>1000) in Python and i wish to combine them into a single column so that i can transfer it into excel in the format that i want it to be.

Eg.

1   100   500   900
2   200   600   1000
3   300   700   1100
4   400   800   1200

into

1  100
2  200
3  300
4  400
5  500
6  600
7  700
8  800
9  900
10 1000
11 1100
12 1200

Any suggestions/solutions are appreciated.

1 Answer 1

1

If you can use pandas, try using Series with flatten:

print(pd.Series(df.values.flatten()))

Edit:

Or if you want to keep the order:

print(pd.concat([df[i] for i in df.columns]).reset_index(drop=True))
Sign up to request clarification or add additional context in comments.

2 Comments

i tried this method but it seems like it rearranges the sequence of my values when in a single column
@jaclynx Check my Edited: section, please accept and upvote if it works :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.