Mary
Mary

Reputation: 45

How do I tell which module a function comes from?

I'm trying to read the help on what various things do as I'm reading through code. I'm getting a bit lost in how to determine which module a function comes from. Here is my current example:

import quandl
import numpy as np
import matplotlib.pyplot as plt
amzn = quandl.get("WIKI/AMZN", start_date="2018-01-01", end_date="2019-01-01")
amzn_daily_close = amzn[['Adj. Close']]
amzn_daily_log_returns = np.log(amzn_daily_close.pct_change()+1)
monthly = amzn.resample('BM').apply(lambda x: x[-1])

So given this block of code, I can do help (quandl.get) to see information about that and help (np.log) to see what that does. But when I get to amzn.resample, where is that resample coming from? What should I be entering to see some help information on the resample stuff?

Upvotes: 3

Views: 1137

Answers (3)

Darius
Darius

Reputation: 12042

Inspection

You can 'inspect' the method to find the implementation:

import inspect

print(inspect.getfile(amzn.resample))

# /opt/miniconda/envs/stackoverflow/lib/python3.6/site-packages/pandas/core/generic.py

IDE

Or you can use a good IDE (e.g. PyCharm or IntelliJ) which supports you with some neat features:

enter image description here enter image description here

Upvotes: 2

Keith
Keith

Reputation: 43024

Generally, these modules should be documented somewhere. They are usually "packaged" and made available on Python Package Index (pypi). You can search there for your package name and find the quandl page. That may have a link to the projects home page with more documentation.

Upvotes: 0

Mithilesh_Kunal
Mithilesh_Kunal

Reputation: 929

Look at the docstring of quandl.get method to get the help message about the return object. This will contain a statement as returns x-object. Googling about x-object will give you more info on this.

Alternatively, you can do this. To identify what is the object you can do the below.

amzn_type = type(amzn)

This gives the monthly object type. Googling for this type value will give you more insights about that object.Example -

a = 10
print(type(a))

The above code returns <class 'int'> output. Googling about int class in python3 will be helpful.

Upvotes: 0

Related Questions