Mahraz
Mahraz

Reputation: 103

A function possible inputs in PYTHON

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.

Upvotes: 0

Views: 501

Answers (4)

blue note
blue note

Reputation: 29081

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.

Upvotes: 0

stark
stark

Reputation: 409

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.

Upvotes: 3

Nicolas Gervais
Nicolas Gervais

Reputation: 36624

You can use the help function:

help(df.hist)

Also:

df.hist? # in ipython only

The possible arguments will print into the console.

Upvotes: 0

gt6989b
gt6989b

Reputation: 4213

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.

Upvotes: 2

Related Questions