0

I have been trying to figure out all day how to stack 24 columns of 100 rows into a single column. I read this in as a pandas DataFrame from a .xlsx file:

df = pd.read_excel('some_groups.xlsx', index_col=[0]

I want the columns to stack directly on top of each other in one column, without altering anything. I have tried looking into melt, stack, and so forth, but my brain is just not getting how to accomplish this.

I have provided an example below of what I am trying to accomplish. PS I am very new to programming, so simple explanations with good examples would be much appreciated. Thank you so much for any help!

starting DataFrame 3 columns A B and C with 4 rows below them:

A B C  
1 5 9  

2 6 10  

3 7 11  

4 8 12  

The result I am wanting is to have a single column (pandas.Series?) with all of the rows stacked on top of one another, in the same order they originally were. :

A  
1  
2  
3  
4  
B  
5  
6  
7  
8  
C  
9  
10  
11  
12

Thanks so much!

Let's try
  • 1,044
  • 9
  • 20
BPhillips
  • 7
  • 3

1 Answers1

0

Thank you @Shubham Sharma. I looked more into df.melt()['value'] as you suggested and that got me to my next step. I greatly appreciate the advice. I ended up using this in my specific instance:
df = pd.melt(df, id_vars=['Boise'])

BPhillips
  • 7
  • 3