Mar-26-2020, 10:01 AM
Hi there,
I am coming from a decade of C# programming to learn python, and trying to wrap my head around how things work.
There seems to be a lot of "magic" in getting the result you want in python.
For example, take the following code:
So we pass the output of numpy.random.normal(...) into pandas.DataFrame(...) to get, according to the docostring, the following assigned to the variable returns:
Two-dimensional size-mutable, potentially heterogeneous tabular data
structure with labeled axes (rows and columns)
Then somehow that data structure contains a method returns.cumprod() which is called to get, according to the docstring, the following assigned to the variable prices:
Return cumulative cumprod over requested axis.
[Insert googling around and experimenting to work out that this means multiplying the first number in the series by the second number, and then the next one by the output of that, and so on.]
The next four lines of code, (how good would it be if notebook had line numbers), are calling methods of the matplotlib.pyplot lib.
So my question is:
As these are completely separate objects in separate namespaces, how does the matplotlib.pyplot know anything about what pandas.DataFrame(...).comprod(...).plot() just did.
Like in C# one object in one namespace knows nothing about another object in a separate namespace that it hasn't been explicitly told, via input methods.
So just trying to get my head around how this all works, so I can build things with a good design, instead of just copying and pasting stuff I google to find that look like they get the output I want.
Like how does scope work with the above code. Lets say I do two plots, how does it know which one to assign the title to?
Thanks for your time/patience,
Kind Regards.
I am coming from a decade of C# programming to learn python, and trying to wrap my head around how things work.
There seems to be a lot of "magic" in getting the result you want in python.
For example, take the following code:
import numpy as np import pandas as pd import matplotlib.pyplot as plt returns = pd.DataFrame(np.random.normal(1.0, 0.03, (100, 10))) prices = returns.cumprod() prices.plot() plt.title('Randomly-generated Prices') plt.xlabel('Time') plt.ylabel('Price') plt.legend(loc=0);This produces a nifty line plot, very nice.
So we pass the output of numpy.random.normal(...) into pandas.DataFrame(...) to get, according to the docostring, the following assigned to the variable returns:
Two-dimensional size-mutable, potentially heterogeneous tabular data
structure with labeled axes (rows and columns)
Then somehow that data structure contains a method returns.cumprod() which is called to get, according to the docstring, the following assigned to the variable prices:
Return cumulative cumprod over requested axis.
[Insert googling around and experimenting to work out that this means multiplying the first number in the series by the second number, and then the next one by the output of that, and so on.]
The next four lines of code, (how good would it be if notebook had line numbers), are calling methods of the matplotlib.pyplot lib.
So my question is:
As these are completely separate objects in separate namespaces, how does the matplotlib.pyplot know anything about what pandas.DataFrame(...).comprod(...).plot() just did.
Like in C# one object in one namespace knows nothing about another object in a separate namespace that it hasn't been explicitly told, via input methods.
So just trying to get my head around how this all works, so I can build things with a good design, instead of just copying and pasting stuff I google to find that look like they get the output I want.
Like how does scope work with the above code. Lets say I do two plots, how does it know which one to assign the title to?
Thanks for your time/patience,
Kind Regards.