Cufflinks provides an interface between Panda's DataFrame
and plotly iplot
in the form of DataFrame.iplot
. The first two output examples below do not surprise me, but the third does. Each is run in a new instance of iPython3.
import pandas as pd
pd.DataFrame.iplot
Out[1]: AttributeError: type object 'DataFrame' has no attribute 'iplot'
import pandas as pd
import cufflinks as cf
pd.DataFrame.iplot
Out[1]: <function cufflinks.plotlytools._iplot>
import cufflinks as cf
import pandas as pd
pd.DataFrame.iplot
Out[1]: <function cufflinks.plotlytools._iplot>
In the first we see pd.DataFrame does not contain iplot
by default. When cufflinks is imported after Pandas in the second example, it could easily add an extra method to the DataFrame
class to provide additional functionality. However, in the third method the DataFrame
class will be defined during the import pandas
statement after cufflinks
has been imported. How is the additional method still added? This is definitely convenient, as my understanding of how the middle example could work would require always importing the libraries in order, which is undesirable, so I would be interested to know the trick used here.