Screen Link: https://app.dataquest.io/m/217/guided-project%3A-analyzing-nyc-high-school-data/1/introduction
Dataquest’s solution Code: combined.corr()["sat_score"][survey_fields].plot.bar()
Other details: I was searching online in pandas documentation and other sites, couldn’t find anything like this: dataframe.corr() with an immediately afterward, without calling an attribute or method, place the ‘sat_score’ combined column and the list of columns survey_fields , with .plot.bar() at the end.
I’ve tried this same code in some formations, and it just works like this, does anyone know where I can find this pythonic possibility of putting everything in one line? what is the link between them, since there is none of that in the documentation
347/5000
1 Like
Everything in Python is actually an object with a type and associated attributes and methods. An attribute is a property of the object that you get or set by giving the object_name + dot + attribute_name, for example img.shape
. A method is a function that the object provides, for example img.argmax(axis=0)
or img.min()
. You can combine methods applying them from left to right.
More info on specific functions:
pandas.DataFrame.corr
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.corr.html
You can use this function like this:
correlations = combined.corr()
correlations = correlations["sat_score"]
or you can simplify this function like this, which will give you totally identical result:
correlations = combined.corr()["sat_score"]
And then you apply .plot.bar()
function to the result:
pandas.DataFrame.plot.bar
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.plot.bar.html
Hope this helps a little bit to understand how it works. If not, please, feel free to ask more questions!
3 Likes
thanks for untangling the code!