Python Forum
This is an Object - Code interpretation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
This is an Object - Code interpretation
#3
(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;number
You 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.
Reply


Messages In This Thread
RE: This is an Object - Code interpretation - by snippsat - Jun-16-2021, 08:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  vars() can't be used in list interpretation? Cheng 3 2,099 Jun-22-2021, 11:59 AM
Last Post: snippsat
  English interpretation of the following file handing snippet mortch 5 3,171 May-30-2019, 08:10 AM
Last Post: mortch
  Code review for S3 object creation beherap 0 2,123 Mar-29-2018, 01:31 PM
Last Post: beherap
  The number of object makes code slower? fig0 1 2,489 Jan-25-2018, 11:16 PM
Last Post: Gribouillis
  Interpretation of a code Alberto 1 2,101 Jan-02-2018, 06:46 PM
Last Post: Windspar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020