0

I have a dataframe with job descriptions in columns and values in rows.

Sample dataframe structure:

           Data Scientist   Senior Data Scientist   Data Engineer
index                   
level_1      94.366197           87.755102          93.650794       
level_2      93.239437           96.938776          95.23809
level_3      38.028169           56.122449          6.349209

dataframe info:

<class 'pandas.core.frame.DataFrame'>
Index: 6 entries, index to Research Analyst
Data columns (total 3 columns):
0    6 non-null object
1    6 non-null object
2    6 non-null object
dtypes: object(3)

I'm trying to replicate an excel output on python by having job descriptions in x-axis and create a bar chart where I can see for every job description what quantity is there for each level. Something like this:enter image description here

What I have so far isn't working:

import matplotlib.pyplot as plt
%matplotlib inline
plt.style.use('ggplot')

degree_table.plot(x=['Data Scientist','Senior Data Scientist', etc.],
                  y=degree_table.index,
                  kind='bar')
4
  • could you share the sample raw data for the dataframe & what's the incorrect output you're getting? Commented Dec 8, 2018 at 5:09
  • I get an error that says x must be a label or position. How can I share the sample raw data on stackoverflow? Commented Dec 8, 2018 at 5:16
  • I hope in your question, 'x=['Data Scientist','Senior Data Scientist', etc.]' the ', etc.' part is only for showing us that there are other columns? Have you tried with a single column? Commented Dec 8, 2018 at 5:19
  • single column didn't work. the answer given worked, thanks for the support tho! Commented Dec 8, 2018 at 5:34

1 Answer 1

2

degree_table.T.plot(kind= 'bar')

The 'T' there, means to transpose the matrix

Easy, try this.

Sign up to request clarification or add additional context in comments.

2 Comments

I get error: TypeError: Empty 'DataFrame': no numeric data to plot
In the dataframe info I see that the values are of type object , you'll have to make them of type float. df.astype(float).T.plot(kind = 'bar')

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.