Stacking dataframes using pandas

Viewed 85

This, apparently simple task, doesn't work. Namely, I need to stack several wines data frames into one big all_wines.

All dfs represent different type of wine with same number of columns (identical variables in dataframe).

red = pd.read_csv(path + 'Red.csv')
red.shape    
(8666, 9)

white = pd.read_csv(path + 'White.csv')
white.shape    
(3763, 9)

sparkling = pd.read_csv(path + 'Sparkling.csv')
sparkling.shape    
(1006, 9)


rose = pd.read_csv(path + 'Rose.csv')
rose.shape    
(396, 9)

all_wines = pd.concat([red, white, sparkling, rose], axis=0)
all_wines.shape    
(13831, 32)

So you can see that every df have 9 columns and various rows. The all_wines should have the same number of columns (since all the observations reefers to same variables). Shape of all_wines should be (allRowsOfWineDataFrames,9) - rather than this result of concat(). How to create data set combining existing dfs "one on top of the other"?

0 Answers
Related