YOU WANG
YOU WANG

Reputation: 41

About pandas python 3

I am a beginner to python 3 and I have a question. In pandas, is read_csv() a class or a method ?

I suspect read_csv() is a class because after you call data = pd.read_csv() , you can subsequently call data.head(), an action only possible with a class, because of plenty of methods within this class.

For example:

from sklearn.impute import SimpleImputer
imp_mean = SimpleImputer( strategy='median') 
imp_mean.fit(impute_num)
imputed_num = imp_mean.transform(impute_num)
imputed_num

As shown above, with the SimpleImputer class, first create an object, and then call the methods from that same object. It appears to be just the same as the pd.read_csv() , so I think read_csv() must be a class.

I just checked the documentation for read_csv(), which claims it returns a dataframe .But if it is a method, why can it continue to use other methods after read_csv()?

from my understanding so far, the method should only return a value and shouldn't continue to use other methods.

Is it necessary to differentiate what type it is when using a new function, method or class? Or should I just think of all of them as an object, because everything in Python is an object.

Upvotes: 1

Views: 49

Answers (2)

Xin Niu
Xin Niu

Reputation: 635

Well my understanding is pd is a class, read_csv() is a method of pd. And the method returns an instance/object of pd (in your case data)

As data is an instance of a class, it should have all the member methods of the class pd.

Upvotes: 0

Mark Snyder
Mark Snyder

Reputation: 1655

It's not a class or a method. It's a function. The resulting DataFrame is just the return value of read_csv(), not an instance of the read_csv class or something like that.

Upvotes: 2

Related Questions