简体   繁体   中英

can I inherit *everything* from pandas (methods, functions, read_csv, etc etc etc etc)

suppose I create a class with my own custom functions. I also want this class to inherit everything from Pandas.

class customClass(pandas.Dataframe):
    def my_func(x,y):
        return x+y.

instantiating

a = customClass()

typing "a." + tab I see I get a lot of pandas methods. but I'm missing somet other things like read_csv. is there a way to get that also? the objective would to just use this custom class for everything.

See the Python tutorial

The most important thing to notice for your specific question is that read_csv is not a method of DataFrame . When you use that method, you call

pd.read_csv("local_file.csv")

not

my_df.read_csv("local_file.csv")

Your customClass does not include that method; it's not reasonable to supposed that your custom instance would show that as a method choice.

For your use case, you would still use pandas.read_csv in building a data frame of your custom class.

If you want to inherit the entire pandas pantheon, then you'll need to do so explicitly. I don't recommend it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM