(Jun-16-2021, 06:50 PM)JoeDainton123 Wrote: I am trying to gain a better understanding of object orientation programming.Pandas is maybe not the best to look at as it really big and dos a lot specialization.
Yoriz explain it fine.
Normally so would
read_csv()
by a method of the class,pandas just write it as a function,then has special
@Appender
decorator.@Appender( _doc_read_csv_and_table.format( func_name="read_csv", summary="Read a comma-separated values (csv) file into DataFrame.", _default_sep="','", storage_options=generic._shared_docs["storage_options"], ) ) def read_csv( filepath_or_buffer: FilePathOrBuffer, sep=lib.no_default, delimiter=None, # Column and Index Locations and Names header="infer", .....ect
If i gone write a demo as more normal OOP class way.
# my_pandas.py class MyPandas: def read_csv(self, file): with open(file) as f: print(f.read()) def head(self, file): with open(file) as f: print(f.read()[:20])Use:
>>> import my_pandas as pd >>> >>> df = pd.MyPandas() >>> df.read_csv('Articles.csv') name;regcode;number Salah;111;22 ali;222;33 Ranard;333;44 >>> >>> df.head('Articles.csv') name;regcode;numberYou see the similarity way of usage now is
read_csv()
and head()
methods of class MyPandas.They are not function as pandas use in there specialization way.