package extension problem
Fabrizio Pollastri
f.pollastri at inrim.it
Mon Feb 13 12:53:27 EST 2012
Ok. To be more clear, consider the real python package Pandas.
This package defines a Series class and a DataFrame class.
The DataFrame is a matrix that can have columns of
different type.
If I write
import pandas as pd
df = pd.DataFrame({'A':[1,2,3],'B':[4,5,6]})
a data frame with two cols named A and B is created.
If I write
col_A = df['A']
the returned col_A is an instance of Series.
Now , let suppose that I want to extend some functionality of pandas
by adding new methods to both Series and DataFrame classes.
One way to do this is to redefine this classes in a new package
(new_pandas) as follow
import pandas as pd
class Series(pd.Series):
...
add new methods
...
class DataFrame(pd.DataFrame):
...
add new methods
...
When I use the new package as a pandas substitute and write
import new_pandas as np
df = np.DataFrame({'A':[1,2,3],'B':[4,5,6]})
col_A = df['A']
col_A is an instance of the original pandas and not of the new pandas,
losing all the added functionality.
Fabrizio
Now, how can I add new methods to extend the functionality of pandas
classes Series and DataFrame
More information about the Python-list
mailing list