How can I quickly check what are the possible inputs to a specific function? For example, I want to plot a histogram for a data frame: df.hist(). I know I can change the bin size, so I know probably there is a way to give the desired bin size as an input to the hist() function. If instead of bins = 10 I use df.hist(bin = 10), Python obviously gives me an error and says hist does not have property bin.
I wonder how I can quickly check what are the possible inputs to a function.
-
8Generally, you need to read the documentation.juanpa.arrivillaga– juanpa.arrivillaga2019年12月02日 17:38:04 +00:00Commented Dec 2, 2019 at 17:38
-
2An editor or IDE with decent completion can help too.Chris– Chris2019年12月02日 17:38:27 +00:00Commented Dec 2, 2019 at 17:38
-
I know the best way is always reading the documentation but sometimes, like the example I described above, you have a good guess of what the input should look like and I was looking for a way to verify quickly.Mahraz– Mahraz2019年12月02日 18:12:46 +00:00Commented Dec 2, 2019 at 18:12
4 Answers 4
Since your question tag contains jupyter notebook I am assuming you are trying on it. So in jupyter notebook 2.0 Shift+Tab would give you function arguments.
Comments
One way is to see if there is documentation on the function itself:
from pandas import DataFrame as DF
help(DF.hist)
Alternatively, if you are inside IPython, using DF.hist? will work as well.
Comments
You can use the help function:
help(df.hist)
Also:
df.hist? # in ipython only
The possible arguments will print into the console.
1 Comment
? suffix syntax isn't part of Python. It's something that iPython adds.You can use the inspect module
def f(x, y):
return x + y
print(inspect.signature(f))
See the documentation of the module for details regarding the returned type.
Comments
Explore related questions
See similar questions with these tags.