plt.close()
sns.barplot(
data=new_df,
x= “location”,
y= “age”
)
plt.show()
What is the argument inside the bracket of this Barplot exercise. I try many things such as “age”, “location” etc.
and come up with errors everytime.
I may be mistaking your issue and apologies if that’s the case but you can hunt down the valid parameters for this function in the seaborn docs: https://seaborn.pydata.org/generated/seaborn.barplot.html
The same page has some usage examples if you scroll down a little.
Newbie here, and from the amount of information, it seems I will be a newbie for a long time.
I have seen lots of code snippets that leave a space after a variable name, for example, x = 4
But other statements have the equal sign without the space, for example, x=4
My question is, does having a spacing between these symbols have any impact on the code? Does it mean the same? Is there any instance where you should have spacing or not?
I can’t think of any situation where this would affect the code. It’s really more of a style thing, your typical assignment example would look like x = 4. Your might skip the whitespaces when using a keyword argument in a function call or when writing default parameters in a function definition-
x = 4
def func(par1=5, par2=10): # defaults typically skip whitespace around operator
result = par1 + par2
return result
func(x, par2=20) # keyword arguments also normally drop the whitespace
When it comes to style there is no accepted answer. If you’re looking for generic guidance then Python’s own suggestion is to use PEP8-
You may find others use different style guidance or they have no style at all , in larger established projects everyone should follow the same rules regardless of your personal preference. But PEP8 is a great place to start.
I see… Yeah, my head was spinning because in some instances I saw the space, in others I didn’t. With more time, it will make more sense. Thanks for your response!
I have a question about the graphs in this exercise. The standard deviation for seaborn.barplot for urban is different than for violinplot. Why does barplot for urban shows small standard deviation and violinplot shows larger? Shouldnt it be that the standard deviation for barplot fir urban is also large?
The line above where age is defined is currently commented out. You’d need to correctly assign that name before you can use it (uncomment the bit with the assignment).
okay, every time i enter the bar plot code, I get a syntax error on line 29 of the code.
File “script.py”, line 29
y= “age”
^
SyntaxError: invalid syntax
For reverence, this is the code section that it is referencing.
plt.close()
sns.barplot(
data=new_df,
x= “location”,
y= “age”
)
plt.show()
not sure what to make of it as my typed in example in script.py looks exactly the same as the codebyte in the exercise, but I get the syntax error no matter what I do to try fixing it