Bar Plot Not Generating

Screen Link:
Schools-Copy1.ipynb (11.9 KB)

My Code:

import matplotlib.pyplot as plt
%matplotlib inline
combined.corr()['sat_score'][survey_fields].plot.bar()
plt.show()

What I expected to happen:
Bar plot to be generated of correlations between survey fields and ‘sat_score’ .

What actually happened:
Nothing. No error.

Replace this line with the output/error


Click here to view the jupyter notebook file in a new tab

@vroomvroom

all_survey = pd.read_csv("schools/survey_all.txt", delimiter="\t", encoding='windows-1252')
d75_survey = pd.read_csv("schools/survey_d75.txt", delimiter="\t", encoding='windows-1252')
survey = pd.concat([all_survey, d75_survey], axis=0)

survey["DBN"] = survey["dbn"]

survey_fields = [
    "DBN", 
    "rr_s", 
    "rr_t", 
    "rr_p", 
    "N_s", 
    "N_t", 
    "N_p", 
    "saf_p_11", 
    "com_p_11", 
    "eng_p_11", 
    "aca_p_11", 
    "saf_t_11", 
    "com_t_11", 
    "eng_t_11", 
    "aca_t_11", 
    "saf_s_11", 
    "com_s_11", 
    "eng_s_11", 
    "aca_s_11", 
    "saf_tot_11", 
    "com_tot_11", 
    "eng_tot_11", 
    "aca_tot_11",
]
survey = survey.loc[:,survey_fields]
data["survey"] = survey

Your mistake is in here, can you spot it? :smiley:

The code for the bar plot was a subcell of

survey_fields.remove("DBN")

So I guess the kernel doesn’t execute a cell if it does not have the line number in front of it.

Hello,
I have viewed your notebook and the cell that this line of code was written is a markdown cell. I think this might be why your cell doesn’t have a line number before it. You can click here to see the shortcut to convert the cell to a code cell, or, you can simply click anywhere on the cell and on the toolbar above the notebook, you’ll see this area:

All you have to do next is to click “code” there and this will convert the markdown cell to a code cell. You can then execute it.

I’d highly recommend you check out this brief introduction to Jupyter Notebook shortcuts. They’ll save you a lot of time.

1 Like

Well, that last element in the list I posted would give a Syntax error right? I’m a bit confused, can we end list with separators these days :open_mouth:

Hello,
I’ve checked it out on the command line Python interpreter and this gave no errors:

a = [3, 2,]

So, I’m guessing that you can end lists with separators, it’s just not a common practice.

1 Like

Oh wow! Thanks @dilarakrby I’ll just make this my signature code quirk from now on. :ok_hand:

1 Like