jonas
jonas

Reputation: 13979

Pandas stack columns in dataframe an make a histogram

I have a dataframe that looks like this:

df_vspd=df.ix[:,['VSPD1','VSPD2','VSPD3','VSPD4','VSPD5','VSPD6','VSPD7']]
df_vspd.head()


   VSPD1  VSPD2  VSPD3  VSPD4  VSPD5  VSPD6  VSPD7
0    NaN    NaN    NaN    NaN    NaN    NaN    NaN
1  21343  37140  30776  12961   1934     14      0
2   6428   9526   9760  12075   4262      0      0
3  11795  14188  16702  18917    612      0      0
4  43571  60684  41611  12168  11264     79      0

I would like to plot a histogram of the data. However I want to stack the columns and do the histogram. Seems like a simple task, however I can not do it!! Help please

What I want to do is stack the columns (VSPD1-VSPD7), and make them the index column. I tried:

cnames = list(df_vspd.columns)
df_test = df_vspd.set_index(cnames).

However it does not do me any good.

Upvotes: 0

Views: 593

Answers (1)

Viktor Kerkez
Viktor Kerkez

Reputation: 46636

Do you want:

df_vspd.stack(0).hist()

Upvotes: 1

Related Questions