Gói cao su trăn

Một chuỗi tài liệu Python là một chuỗi được sử dụng để ghi lại một mô-đun, lớp, hàm hoặc phương thức Python, vì vậy các lập trình viên có thể hiểu nó làm gì mà không cần phải đọc chi tiết về cách triển khai

Ngoài ra, thực tế phổ biến là tự động tạo tài liệu trực tuyến [html] từ chuỗi tài liệu. Nhân sư phục vụ mục đích này

Ví dụ tiếp theo đưa ra ý tưởng về một chuỗi tài liệu trông như thế nào

def add[num1, num2]:
    """
    Add up two integer numbers.

    This function simply wraps the ``+`` operator, and does not
    do anything interesting, except for illustrating what
    the docstring of a very simple function looks like.

    Parameters
    ----------
    num1 : int
        First number to add.
    num2 : int
        Second number to add.

    Returns
    -------
    int
        The sum of ``num1`` and ``num2``.

    See Also
    --------
    subtract : Subtract one integer from another.

    Examples
    --------
    >>> add[2, 2]
    4
    >>> add[25, 0]
    25
    >>> add[10, -10]
    0
    """
    return num1 + num2

Một số tiêu chuẩn liên quan đến chuỗi tài liệu tồn tại, giúp chúng dễ đọc hơn và cho phép dễ dàng xuất chúng sang các định dạng khác như html hoặc pdf

Các quy ước đầu tiên mà mọi chuỗi tài liệu Python phải tuân theo được xác định trong PEP-257

Vì PEP-257 khá rộng nên các tiêu chuẩn khác cụ thể hơn cũng tồn tại. Trong trường hợp gấu trúc, quy ước chuỗi tài liệu NumPy được tuân theo. Các quy ước này được giải thích trong tài liệu này

  • hướng dẫn chuỗi tài liệu numpydoc [dựa trên tài liệu Hướng dẫn ban đầu về tài liệu NumPy/SciPy]

numpydoc là một tiện ích mở rộng của Sphinx để hỗ trợ quy ước chuỗi tài liệu NumPy

Tiêu chuẩn sử dụng reStructuredText [reST]. reStructuredText là ngôn ngữ đánh dấu cho phép mã hóa các kiểu trong tệp văn bản thuần túy. Tài liệu về reStructuredText có thể được tìm thấy trong

  • Sphinx reStructuredText primer

  • Tái cấu trúc nhanhTham khảo văn bản

  • Thông số kỹ thuật tái cấu trúc đầy đủ

gấu trúc có một số người trợ giúp để chia sẻ tài liệu giữa các lớp liên quan, xem

Phần còn lại của tài liệu này sẽ tóm tắt tất cả các hướng dẫn ở trên và sẽ cung cấp các quy ước bổ sung dành riêng cho dự án gấu trúc

Viết một chuỗi tài liệu

quy tắc chung

Các tài liệu phải được xác định bằng ba dấu ngoặc kép. Không được để trống dòng nào trước hoặc sau chuỗi tài liệu. Văn bản bắt đầu ở dòng tiếp theo sau dấu ngoặc kép mở đầu. Các trích dẫn kết thúc có dòng riêng [có nghĩa là chúng không ở cuối câu cuối cùng]

Trong một số trường hợp hiếm hoi, các kiểu còn lại như văn bản in đậm hoặc in nghiêng sẽ được sử dụng trong chuỗi tài liệu, nhưng mã nội tuyến thường được trình bày giữa các dấu gạch ngược. Sau đây được coi là mã nội tuyến

  • Tên của một tham số

  • Mã Python, một mô-đun, chức năng, tích hợp sẵn, loại, chữ… [e. g.

    def func[]:
    
        """Some function.
    
        With several mistakes in the docstring.
    
        It has a blank like after the signature ``def func[]:``.
    
        The text 'Some function' should go in the line after the
        opening quotes of the docstring, not in the same line.
    
        There is a blank line between the docstring and the first line
        of code ``foo = 1``.
    
        The closing quotes should be in the next line, not in this one."""
    
        foo = 1
        bar = 2
        return foo + bar
    
    8,
    def func[]:
    
        """Some function.
    
        With several mistakes in the docstring.
    
        It has a blank like after the signature ``def func[]:``.
    
        The text 'Some function' should go in the line after the
        opening quotes of the docstring, not in the same line.
    
        There is a blank line between the docstring and the first line
        of code ``foo = 1``.
    
        The closing quotes should be in the next line, not in this one."""
    
        foo = 1
        bar = 2
        return foo + bar
    
    9,
    def astype[dtype]:
        """
        Cast Series type.
    
        This section will provide further details.
        """
        pass
    
    0,
    def astype[dtype]:
        """
        Cast Series type.
    
        This section will provide further details.
        """
        pass
    
    1,
    def astype[dtype]:
        """
        Cast Series type.
    
        This section will provide further details.
        """
        pass
    
    2]

  • Một lớp gấu trúc [ở dạng

    def astype[dtype]:
        """
        Cast Series type.
    
        This section will provide further details.
        """
        pass
    
    3]

  • Phương pháp gấu trúc [ở dạng

    def astype[dtype]:
        """
        Cast Series type.
    
        This section will provide further details.
        """
        pass
    
    4]

  • Hàm pandas [ở dạng

    def astype[dtype]:
        """
        Cast Series type.
    
        This section will provide further details.
        """
        pass
    
    5]

Ghi chú

Để chỉ hiển thị thành phần cuối cùng của lớp, phương thức hoặc chức năng được liên kết, hãy thêm tiền tố vào nó bằng ______3_______6. Ví dụ:

def astype[dtype]:
    """
    Cast Series type.

    This section will provide further details.
    """
    pass
7 sẽ liên kết tới
def astype[dtype]:
    """
    Cast Series type.

    This section will provide further details.
    """
    pass
8 nhưng chỉ hiển thị phần cuối cùng,
def astype[dtype]:
    """
    Cast Series type.

    This section will provide further details.
    """
    pass
9 dưới dạng văn bản liên kết. Xem để biết chi tiết

Tốt

def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]

Xấu

def func[]:

    """Some function.

    With several mistakes in the docstring.

    It has a blank like after the signature ``def func[]:``.

    The text 'Some function' should go in the line after the
    opening quotes of the docstring, not in the same line.

    There is a blank line between the docstring and the first line
    of code ``foo = 1``.

    The closing quotes should be in the next line, not in this one."""

    foo = 1
    bar = 2
    return foo + bar

Phần 1. tóm tắt ngắn

Tóm tắt ngắn gọn là một câu duy nhất diễn đạt những gì chức năng thực hiện một cách ngắn gọn

Tóm tắt ngắn phải bắt đầu bằng chữ in hoa, kết thúc bằng dấu chấm và nằm trong một dòng. Nó cần thể hiện những gì đối tượng làm mà không cung cấp chi tiết. Đối với các hàm và phương thức, phần tóm tắt ngắn phải bắt đầu bằng một động từ nguyên thể

Tốt

def astype[dtype]:
    """
    Cast Series type.

    This section will provide further details.
    """
    pass

Xấu

def astype[dtype]:
    """
    Casts Series type.

    Verb in third-person of the present simple, should be infinitive.
    """
    pass

def astype[dtype]:
    """
    Method to cast Series type.

    Does not start with verb.
    """
    pass

def astype[dtype]:
    """
    Cast Series type

    Missing dot at the end.
    """
    pass

def astype[dtype]:
    """
    Cast Series type from its current type to the new type defined in
    the parameter dtype.

    Summary is too verbose and doesn't fit in a single line.
    """
    pass

Phần 2. tóm tắt mở rộng

Tóm tắt mở rộng cung cấp chi tiết về những gì chức năng làm. Nó không nên đi sâu vào chi tiết của các thông số, hoặc thảo luận về ghi chú thực hiện, mà sẽ đi vào các phần khác

Một dòng trống được để lại giữa phần tóm tắt ngắn và phần tóm tắt mở rộng. Mỗi đoạn trong phần tóm tắt mở rộng đều kết thúc bằng dấu chấm

Phần tóm tắt mở rộng sẽ cung cấp chi tiết về lý do tại sao chức năng này hữu ích và các trường hợp sử dụng của chúng, nếu nó không quá chung chung

def unstack[]:
    """
    Pivot a row index to columns.

    When using a MultiIndex, a level can be pivoted so each value in
    the index becomes a column. This is especially useful when a subindex
    is repeated for the main index, and data is easier to visualize as a
    pivot table.

    The index level will be automatically removed from the index when added
    as columns.
    """
    pass

Phần 3. thông số

Chi tiết các tham số sẽ được bổ sung trong phần này. Phần này có tiêu đề “Thông số”, theo sau là một dòng có dấu gạch nối dưới mỗi chữ cái của từ “Thông số”. Một dòng trống được để lại trước tiêu đề của phần, nhưng không phải sau và không phải giữa dòng có từ "Tham số" và dòng có dấu gạch nối

Sau tiêu đề, mỗi thông số trong chữ ký phải được ghi lại, bao gồm

def astype[dtype]:
    """
    Casts Series type.

    Verb in third-person of the present simple, should be infinitive.
    """
    pass
0 và
def astype[dtype]:
    """
    Casts Series type.

    Verb in third-person of the present simple, should be infinitive.
    """
    pass
1, nhưng không phải
def astype[dtype]:
    """
    Casts Series type.

    Verb in third-person of the present simple, should be infinitive.
    """
    pass
2

Các tham số được xác định theo tên của chúng, theo sau là khoảng trắng, dấu hai chấm, dấu cách khác và loại [hoặc các loại]. Lưu ý rằng khoảng cách giữa tên và dấu hai chấm rất quan trọng. Các loại không được xác định cho

def astype[dtype]:
    """
    Casts Series type.

    Verb in third-person of the present simple, should be infinitive.
    """
    pass
0 và
def astype[dtype]:
    """
    Casts Series type.

    Verb in third-person of the present simple, should be infinitive.
    """
    pass
1, nhưng phải được xác định cho tất cả các tham số khác. Sau phần định nghĩa tham số bắt buộc phải có một dòng mô tả tham số, được thụt vào trong, có thể có nhiều dòng. Mô tả phải bắt đầu bằng chữ in hoa và kết thúc bằng dấu chấm

Đối với các đối số từ khóa có giá trị mặc định, giá trị mặc định sẽ được liệt kê sau dấu phẩy ở cuối loại. Hình thức chính xác của loại trong trường hợp này sẽ là “int, default 0”. Trong một số trường hợp, có thể hữu ích khi giải thích đối số mặc định nghĩa là gì, có thể được thêm vào sau dấu phẩy “int, default -1, có nghĩa là tất cả cpus”

Trong trường hợp giá trị mặc định là

def astype[dtype]:
    """
    Casts Series type.

    Verb in third-person of the present simple, should be infinitive.
    """
    pass
5, nghĩa là giá trị đó sẽ không được sử dụng. Thay vì
def astype[dtype]:
    """
    Casts Series type.

    Verb in third-person of the present simple, should be infinitive.
    """
    pass
6, nên viết
def astype[dtype]:
    """
    Casts Series type.

    Verb in third-person of the present simple, should be infinitive.
    """
    pass
7. Khi
def astype[dtype]:
    """
    Casts Series type.

    Verb in third-person of the present simple, should be infinitive.
    """
    pass
5 là một giá trị đang được sử dụng, chúng tôi sẽ giữ nguyên dạng “str, default Không có”. Ví dụ: trong
def astype[dtype]:
    """
    Casts Series type.

    Verb in third-person of the present simple, should be infinitive.
    """
    pass
9,
def astype[dtype]:
    """
    Casts Series type.

    Verb in third-person of the present simple, should be infinitive.
    """
    pass
5 không phải là giá trị đang được sử dụng, nhưng có nghĩa là tính năng nén là tùy chọn và không có tính năng nén nào được sử dụng nếu không được cung cấp. Trong trường hợp này, chúng tôi sẽ sử dụng
def astype[dtype]:
    """
    Casts Series type.

    Verb in third-person of the present simple, should be infinitive.
    """
    pass
7. Chỉ trong các trường hợp như
def astype[dtype]:
    """
    Method to cast Series type.

    Does not start with verb.
    """
    pass
2 và
def astype[dtype]:
    """
    Casts Series type.

    Verb in third-person of the present simple, should be infinitive.
    """
    pass
5 đang được sử dụng giống như cách mà
def astype[dtype]:
    """
    Method to cast Series type.

    Does not start with verb.
    """
    pass
4 hoặc
def astype[dtype]:
    """
    Method to cast Series type.

    Does not start with verb.
    """
    pass
5 sẽ được sử dụng, thì chúng tôi sẽ chỉ định “str, int hoặc Không, mặc định là Không”

Tốt

class Series:
    def plot[self, kind, color='blue', **kwargs]:
        """
        Generate a plot.

        Render the data in the Series as a matplotlib plot of the
        specified kind.

        Parameters
        ----------
        kind : str
            Kind of matplotlib plot.
        color : str, default 'blue'
            Color name or rgb code.
        **kwargs
            These parameters will be passed to the matplotlib plotting
            function.
        """
        pass

Xấu

def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
0

các loại tham số

Khi chỉ định các loại tham số, có thể sử dụng trực tiếp các loại dữ liệu tích hợp sẵn của Python [loại Python được ưa thích hơn chuỗi dài dòng, số nguyên, boolean, v.v.]

  • int

  • trôi nổi

  • str

  • bool

Đối với các loại phức tạp, xác định các loại phụ. Đối với

def astype[dtype]:
    """
    Method to cast Series type.

    Does not start with verb.
    """
    pass
6 và
def astype[dtype]:
    """
    Method to cast Series type.

    Does not start with verb.
    """
    pass
7, vì có nhiều hơn một loại, chúng tôi sử dụng dấu ngoặc để giúp đọc loại [dấu ngoặc nhọn cho
def astype[dtype]:
    """
    Method to cast Series type.

    Does not start with verb.
    """
    pass
6 và dấu ngoặc vuông bình thường cho
def astype[dtype]:
    """
    Method to cast Series type.

    Does not start with verb.
    """
    pass
7]

  • danh sách int

  • lệnh của {str. int}

  • bộ của [str, int, int]

  • bộ của [str,]

  • bộ str

Trong trường hợp chỉ có một bộ giá trị được phép, hãy liệt kê chúng trong dấu ngoặc nhọn và phân tách bằng dấu phẩy [theo sau là khoảng trắng]. Nếu các giá trị là thứ tự và chúng có thứ tự, hãy liệt kê chúng theo thứ tự này. Nếu không, hãy liệt kê giá trị mặc định trước, nếu có

  • {0, 10, 25}

  • {'đơn giản', 'nâng cao'}

  • {'thấp trung bình cao'}

  • {'mèo', 'chó', 'chim'}

Nếu loại được xác định trong mô-đun Python, thì mô-đun đó phải được chỉ định

  • ngày giờ. ngày

  • ngày giờ. ngày giờ

  • số thập phân. Số thập phân

Nếu loại nằm trong một gói, mô-đun cũng phải được chỉ định

  • cục mịch. ndarray

  • scipy. thưa thớt. coo_matrix

Nếu loại là loại gấu trúc, hãy chỉ định gấu trúc ngoại trừ Sê-ri và Khung dữ liệu

  • Loạt

  • Khung dữ liệu

  • gấu trúc. Mục lục

  • gấu trúc. phân loại

  • gấu trúc. mảng. mảng thưa thớt

Nếu loại chính xác không liên quan, nhưng phải tương thích với một mảng NumPy, thì có thể chỉ định giống như mảng. Nếu bất kỳ loại nào có thể lặp lại được chấp nhận, thì có thể sử dụng iterable

  • dạng mảng

  • lặp đi lặp lại

Nếu nhiều hơn một loại được chấp nhận, hãy phân tách chúng bằng dấu phẩy, ngoại trừ hai loại cuối cùng, cần được phân tách bằng từ 'hoặc'

  • int hoặc float

  • phao, số thập phân. Số thập phân hoặc Không có

  • str hoặc danh sách str

Nếu

def astype[dtype]:
    """
    Casts Series type.

    Verb in third-person of the present simple, should be infinitive.
    """
    pass
5 là một trong các giá trị được chấp nhận, thì giá trị đó luôn phải là giá trị cuối cùng trong danh sách

Đối với trục, quy ước là sử dụng một cái gì đó như

  • trục. {0 hoặc 'chỉ mục', 1 hoặc 'cột', Không có}, mặc định Không có

phần 4. lợi nhuận hoặc sản lượng

Nếu phương thức trả về một giá trị, nó sẽ được ghi lại trong phần này. Ngoài ra nếu phương thức mang lại đầu ra của nó

Tiêu đề của phần sẽ được xác định theo cách tương tự như “Thông số”. Với các tên “Returns” hoặc “Yields” theo sau là một dòng có nhiều dấu gạch nối bằng các chữ cái trong từ trước đó

Các tài liệu của sự trở lại cũng tương tự như các thông số. Nhưng trong trường hợp này, sẽ không có tên nào được cung cấp, trừ khi phương thức trả về hoặc mang lại nhiều hơn một giá trị [một bộ giá trị]

Các loại cho “Lợi nhuận” và “Lợi nhuận” giống như các loại cho “Tham số”. Ngoài ra, phần mô tả phải kết thúc bằng dấu chấm

Ví dụ, với một giá trị duy nhất

def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
1

Với nhiều hơn một giá trị

def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
2

Nếu phương pháp mang lại giá trị của nó

def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
3

Phần 5. Xem thêm

Phần này được sử dụng để cho người dùng biết về chức năng gấu trúc liên quan đến chức năng đang được ghi lại. Trong một số ít trường hợp, nếu không tìm thấy phương thức hoặc chức năng liên quan nào, phần này có thể được bỏ qua

Một ví dụ rõ ràng sẽ là các phương thức

def astype[dtype]:
    """
    Cast Series type

    Missing dot at the end.
    """
    pass
1 và
def astype[dtype]:
    """
    Cast Series type

    Missing dot at the end.
    """
    pass
2. Vì
def astype[dtype]:
    """
    Cast Series type

    Missing dot at the end.
    """
    pass
2 tương đương với
def astype[dtype]:
    """
    Cast Series type

    Missing dot at the end.
    """
    pass
1 nhưng ở cuối
def astype[dtype]:
    """
    Cast Series type.

    This section will provide further details.
    """
    pass
9 hoặc
def astype[dtype]:
    """
    Cast Series type

    Missing dot at the end.
    """
    pass
6 thay vì ở đầu, bạn nên cho người dùng biết về điều đó

Để đưa ra một trực giác về những gì có thể được coi là liên quan, đây là một số ví dụ

  • def astype[dtype]:
        """
        Cast Series type
    
        Missing dot at the end.
        """
        pass
    
    7 và
    def astype[dtype]:
        """
        Cast Series type
    
        Missing dot at the end.
        """
        pass
    
    8, khi họ làm như vậy, nhưng trong một trường hợp cung cấp các chỉ số và ở các vị trí khác

  • def astype[dtype]:
        """
        Cast Series type
    
        Missing dot at the end.
        """
        pass
    
    9 và
    def astype[dtype]:
        """
        Cast Series type from its current type to the new type defined in
        the parameter dtype.
    
        Summary is too verbose and doesn't fit in a single line.
        """
        pass
    
    0, khi chúng làm ngược lại

  • def astype[dtype]:
        """
        Cast Series type from its current type to the new type defined in
        the parameter dtype.
    
        Summary is too verbose and doesn't fit in a single line.
        """
        pass
    
    1,
    def astype[dtype]:
        """
        Cast Series type from its current type to the new type defined in
        the parameter dtype.
    
        Summary is too verbose and doesn't fit in a single line.
        """
        pass
    
    2 và
    def astype[dtype]:
        """
        Cast Series type from its current type to the new type defined in
        the parameter dtype.
    
        Summary is too verbose and doesn't fit in a single line.
        """
        pass
    
    3, vì người dùng dễ dàng tìm kiếm phương thức lặp qua các cột lại kết thúc bằng phương thức lặp qua hàng và ngược lại

  • def astype[dtype]:
        """
        Cast Series type from its current type to the new type defined in
        the parameter dtype.
    
        Summary is too verbose and doesn't fit in a single line.
        """
        pass
    
    4 và
    def astype[dtype]:
        """
        Cast Series type from its current type to the new type defined in
        the parameter dtype.
    
        Summary is too verbose and doesn't fit in a single line.
        """
        pass
    
    5, vì cả hai phương pháp đều được sử dụng để xử lý các giá trị bị thiếu

  • def astype[dtype]:
        """
        Cast Series type from its current type to the new type defined in
        the parameter dtype.
    
        Summary is too verbose and doesn't fit in a single line.
        """
        pass
    
    6 và
    def astype[dtype]:
        """
        Cast Series type from its current type to the new type defined in
        the parameter dtype.
    
        Summary is too verbose and doesn't fit in a single line.
        """
        pass
    
    7, vì chúng bổ sung cho nhau

  • def astype[dtype]:
        """
        Cast Series type from its current type to the new type defined in
        the parameter dtype.
    
        Summary is too verbose and doesn't fit in a single line.
        """
        pass
    
    8 và
    def astype[dtype]:
        """
        Cast Series type from its current type to the new type defined in
        the parameter dtype.
    
        Summary is too verbose and doesn't fit in a single line.
        """
        pass
    
    9, vì cái này là sự tổng quát hóa của cái kia

  • def unstack[]:
        """
        Pivot a row index to columns.
    
        When using a MultiIndex, a level can be pivoted so each value in
        the index becomes a column. This is especially useful when a subindex
        is repeated for the main index, and data is easier to visualize as a
        pivot table.
    
        The index level will be automatically removed from the index when added
        as columns.
        """
        pass
    
    0 và
    def unstack[]:
        """
        Pivot a row index to columns.
    
        When using a MultiIndex, a level can be pivoted so each value in
        the index becomes a column. This is especially useful when a subindex
        is repeated for the main index, and data is easier to visualize as a
        pivot table.
    
        The index level will be automatically removed from the index when added
        as columns.
        """
        pass
    
    1, vì người dùng có thể đang đọc tài liệu về
    def unstack[]:
        """
        Pivot a row index to columns.
    
        When using a MultiIndex, a level can be pivoted so each value in
        the index becomes a column. This is especially useful when a subindex
        is repeated for the main index, and data is easier to visualize as a
        pivot table.
    
        The index level will be automatically removed from the index when added
        as columns.
        """
        pass
    
    0 để biết cách bỏ ngày tháng và cách thực hiện là với
    def unstack[]:
        """
        Pivot a row index to columns.
    
        When using a MultiIndex, a level can be pivoted so each value in
        the index becomes a column. This is especially useful when a subindex
        is repeated for the main index, and data is easier to visualize as a
        pivot table.
    
        The index level will be automatically removed from the index when added
        as columns.
        """
        pass
    
    1

  • def unstack[]:
        """
        Pivot a row index to columns.
    
        When using a MultiIndex, a level can be pivoted so each value in
        the index becomes a column. This is especially useful when a subindex
        is repeated for the main index, and data is easier to visualize as a
        pivot table.
    
        The index level will be automatically removed from the index when added
        as columns.
        """
        pass
    
    4 có liên quan đến
    def unstack[]:
        """
        Pivot a row index to columns.
    
        When using a MultiIndex, a level can be pivoted so each value in
        the index becomes a column. This is especially useful when a subindex
        is repeated for the main index, and data is easier to visualize as a
        pivot table.
    
        The index level will be automatically removed from the index when added
        as columns.
        """
        pass
    
    5, vì chức năng của nó dựa trên nó

Khi quyết định những gì có liên quan, bạn chủ yếu nên sử dụng cảm giác thông thường của mình và suy nghĩ về những gì có thể hữu ích cho người dùng đọc tài liệu, đặc biệt là những người ít kinh nghiệm hơn

Khi liên quan đến các thư viện khác [chủ yếu là

def unstack[]:
    """
    Pivot a row index to columns.

    When using a MultiIndex, a level can be pivoted so each value in
    the index becomes a column. This is especially useful when a subindex
    is repeated for the main index, and data is easier to visualize as a
    pivot table.

    The index level will be automatically removed from the index when added
    as columns.
    """
    pass
6], trước tiên hãy sử dụng tên của mô-đun [không phải bí danh như
def unstack[]:
    """
    Pivot a row index to columns.

    When using a MultiIndex, a level can be pivoted so each value in
    the index becomes a column. This is especially useful when a subindex
    is repeated for the main index, and data is easier to visualize as a
    pivot table.

    The index level will be automatically removed from the index when added
    as columns.
    """
    pass
7]. Nếu chức năng nằm trong một mô-đun không phải là mô-đun chính, chẳng hạn như
def unstack[]:
    """
    Pivot a row index to columns.

    When using a MultiIndex, a level can be pivoted so each value in
    the index becomes a column. This is especially useful when a subindex
    is repeated for the main index, and data is easier to visualize as a
    pivot table.

    The index level will be automatically removed from the index when added
    as columns.
    """
    pass
8, hãy liệt kê mô-đun đầy đủ [e. g.
def unstack[]:
    """
    Pivot a row index to columns.

    When using a MultiIndex, a level can be pivoted so each value in
    the index becomes a column. This is especially useful when a subindex
    is repeated for the main index, and data is easier to visualize as a
    pivot table.

    The index level will be automatically removed from the index when added
    as columns.
    """
    pass
9]

Phần này có tiêu đề, “Xem thêm” [lưu ý chữ S và A viết hoa], theo sau là dòng có dấu gạch ngang và phía trước là dòng trống

Sau tiêu đề, chúng tôi sẽ thêm một dòng cho từng phương thức hoặc chức năng có liên quan, theo sau là khoảng trắng, dấu hai chấm, một khoảng trắng khác và một mô tả ngắn minh họa chức năng của phương thức hoặc chức năng này, tại sao nó có liên quan trong ngữ cảnh này và điều gì . Phần mô tả cũng phải kết thúc bằng dấu chấm

Lưu ý rằng trong "Returns" và "Yields", mô tả nằm trên dòng sau loại. Tuy nhiên, trong phần này, nó nằm trên cùng một dòng, với dấu hai chấm ở giữa. Nếu mô tả không vừa trên cùng một dòng, nó có thể tiếp tục trên các dòng khác và phải được thụt vào thêm

Ví dụ

def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
4

Phần 6. ghi chú

Đây là phần tùy chọn được sử dụng để ghi chú về việc triển khai thuật toán hoặc để ghi lại các khía cạnh kỹ thuật của hành vi chức năng

Vui lòng bỏ qua nó, trừ khi bạn đã quen với việc triển khai thuật toán hoặc bạn phát hiện ra một số hành vi phản trực giác trong khi viết các ví dụ cho hàm

Phần này tuân theo định dạng giống như phần tóm tắt mở rộng

Phần 7. ví dụ

Đây là một trong những phần quan trọng nhất của chuỗi tài liệu, mặc dù được đặt ở vị trí cuối cùng, vì mọi người thường hiểu các khái niệm tốt hơn bằng ví dụ hơn là thông qua giải thích chính xác

Các ví dụ trong tài liệu, bên cạnh việc minh họa cách sử dụng hàm hoặc phương thức, phải là mã Python hợp lệ, trả về đầu ra đã cho theo cách xác định và người dùng có thể sao chép và chạy

Các ví dụ được trình bày dưới dạng phiên trong thiết bị đầu cuối Python.

class Series:
    def plot[self, kind, color='blue', **kwargs]:
        """
        Generate a plot.

        Render the data in the Series as a matplotlib plot of the
        specified kind.

        Parameters
        ----------
        kind : str
            Kind of matplotlib plot.
        color : str, default 'blue'
            Color name or rgb code.
        **kwargs
            These parameters will be passed to the matplotlib plotting
            function.
        """
        pass
0 được sử dụng để trình bày mã.
class Series:
    def plot[self, kind, color='blue', **kwargs]:
        """
        Generate a plot.

        Render the data in the Series as a matplotlib plot of the
        specified kind.

        Parameters
        ----------
        kind : str
            Kind of matplotlib plot.
        color : str, default 'blue'
            Color name or rgb code.
        **kwargs
            These parameters will be passed to the matplotlib plotting
            function.
        """
        pass
1 được sử dụng cho mã tiếp tục từ dòng trước. Đầu ra được trình bày ngay sau dòng mã cuối cùng tạo đầu ra [không có dòng trống ở giữa]. Nhận xét mô tả các ví dụ có thể được thêm vào với các dòng trống trước và sau chúng

Cách trình bày ví dụ như sau

  1. Nhập các thư viện bắt buộc [ngoại trừ

    def unstack[]:
        """
        Pivot a row index to columns.
    
        When using a MultiIndex, a level can be pivoted so each value in
        the index becomes a column. This is especially useful when a subindex
        is repeated for the main index, and data is easier to visualize as a
        pivot table.
    
        The index level will be automatically removed from the index when added
        as columns.
        """
        pass
    
    6 và
    class Series:
        def plot[self, kind, color='blue', **kwargs]:
            """
            Generate a plot.
    
            Render the data in the Series as a matplotlib plot of the
            specified kind.
    
            Parameters
            ----------
            kind : str
                Kind of matplotlib plot.
            color : str, default 'blue'
                Color name or rgb code.
            **kwargs
                These parameters will be passed to the matplotlib plotting
                function.
            """
            pass
    
    3]

  2. Tạo dữ liệu cần thiết cho ví dụ

  3. Hiển thị một ví dụ rất cơ bản đưa ra ý tưởng về trường hợp sử dụng phổ biến nhất

  4. Thêm các ví dụ có giải thích minh họa cách sử dụng các tham số cho chức năng mở rộng

Một ví dụ đơn giản có thể là

def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
5

Các ví dụ nên ngắn gọn nhất có thể. Trong trường hợp độ phức tạp của hàm yêu cầu các ví dụ dài, nên sử dụng các khối có tiêu đề in đậm. Sử dụng dấu sao kép

class Series:
    def plot[self, kind, color='blue', **kwargs]:
        """
        Generate a plot.

        Render the data in the Series as a matplotlib plot of the
        specified kind.

        Parameters
        ----------
        kind : str
            Kind of matplotlib plot.
        color : str, default 'blue'
            Color name or rgb code.
        **kwargs
            These parameters will be passed to the matplotlib plotting
            function.
        """
        pass
4 để in đậm văn bản, như trong
class Series:
    def plot[self, kind, color='blue', **kwargs]:
        """
        Generate a plot.

        Render the data in the Series as a matplotlib plot of the
        specified kind.

        Parameters
        ----------
        kind : str
            Kind of matplotlib plot.
        color : str, default 'blue'
            Color name or rgb code.
        **kwargs
            These parameters will be passed to the matplotlib plotting
            function.
        """
        pass
5

Quy ước cho các ví dụ

Mã trong các ví dụ được giả định là luôn bắt đầu bằng hai dòng này không được hiển thị

def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
6

Bất kỳ mô-đun nào khác được sử dụng trong các ví dụ đều phải được nhập rõ ràng, mỗi mô-đun trên một dòng [như khuyến nghị trong ] và tránh các bí danh. Tránh nhập quá nhiều, nhưng nếu cần, hãy nhập từ thư viện chuẩn trước, tiếp theo là thư viện của bên thứ ba [như matplotlib]

Khi minh họa các ví dụ bằng một

def astype[dtype]:
    """
    Cast Series type.

    This section will provide further details.
    """
    pass
9, hãy sử dụng tên
class Series:
    def plot[self, kind, color='blue', **kwargs]:
        """
        Generate a plot.

        Render the data in the Series as a matplotlib plot of the
        specified kind.

        Parameters
        ----------
        kind : str
            Kind of matplotlib plot.
        color : str, default 'blue'
            Color name or rgb code.
        **kwargs
            These parameters will be passed to the matplotlib plotting
            function.
        """
        pass
7 và nếu minh họa bằng một
def astype[dtype]:
    """
    Cast Series type

    Missing dot at the end.
    """
    pass
6, hãy sử dụng tên
class Series:
    def plot[self, kind, color='blue', **kwargs]:
        """
        Generate a plot.

        Render the data in the Series as a matplotlib plot of the
        specified kind.

        Parameters
        ----------
        kind : str
            Kind of matplotlib plot.
        color : str, default 'blue'
            Color name or rgb code.
        **kwargs
            These parameters will be passed to the matplotlib plotting
            function.
        """
        pass
9. Đối với các chỉ số,
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
00 là tên ưa thích. Nếu sử dụng một bộ đồng nhất
def astype[dtype]:
    """
    Cast Series type.

    This section will provide further details.
    """
    pass
9 hoặc
def astype[dtype]:
    """
    Cast Series type

    Missing dot at the end.
    """
    pass
6, hãy đặt tên cho chúng là
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
03,
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
04,
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
05… hoặc
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
06,
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
07,
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
08… Nếu dữ liệu không đồng nhất và cần nhiều hơn một cấu trúc, hãy đặt tên cho chúng bằng một cái gì đó có ý nghĩa, ví dụ như
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
09

Dữ liệu được sử dụng trong ví dụ phải càng nhỏ gọn càng tốt. Số lượng hàng được khuyến nghị là khoảng 4, nhưng hãy đặt nó thành một số có ý nghĩa đối với ví dụ cụ thể. Ví dụ trong phương thức

def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
11, nó yêu cầu phải cao hơn 5, để hiển thị ví dụ với các giá trị mặc định. Nếu thực hiện
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
12, chúng ta có thể sử dụng một cái gì đó như
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
13, vì vậy dễ dàng thấy rằng giá trị được trả về là giá trị trung bình

Đối với các ví dụ phức tạp hơn [ví dụ nhóm], tránh sử dụng dữ liệu mà không có diễn giải, chẳng hạn như ma trận các số ngẫu nhiên có các cột A, B, C, D… Thay vào đó, hãy sử dụng một ví dụ có ý nghĩa, giúp dễ hiểu khái niệm hơn. Trừ khi được yêu cầu bởi ví dụ, sử dụng tên của động vật, để giữ cho các ví dụ nhất quán. Và tính chất số của chúng

Khi gọi phương thức, các đối số từ khóa

def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
14 được ưu tiên hơn các đối số vị trí
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
15

Tốt

def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
7

Xấu

def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
8

Mẹo để lấy ví dụ của bạn vượt qua các tài liệu

Việc lấy các ví dụ vượt qua các tài liệu trong tập lệnh xác thực đôi khi có thể khó khăn. Dưới đây là một số điểm chú ý

  • Nhập tất cả các thư viện cần thiết [ngoại trừ pandas và NumPy, những thư viện này đã được nhập dưới dạng

    def add_values[arr]:
        """
        Add the values in ``arr``.
    
        This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.
    
        Some sections are omitted here for simplicity.
        """
        return sum[arr]
    
    16 và
    def add_values[arr]:
        """
        Add the values in ``arr``.
    
        This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.
    
        Some sections are omitted here for simplicity.
        """
        return sum[arr]
    
    17] và xác định tất cả các biến bạn sử dụng trong ví dụ

  • Cố gắng tránh sử dụng dữ liệu ngẫu nhiên. Tuy nhiên, dữ liệu ngẫu nhiên có thể ổn trong một số trường hợp, chẳng hạn như nếu hàm bạn đang ghi lại liên quan đến phân phối xác suất hoặc nếu lượng dữ liệu cần thiết để làm cho kết quả của hàm có ý nghĩa là quá nhiều, thì việc tạo thủ công sẽ rất cồng kềnh. Trong những trường hợp đó, hãy luôn sử dụng một nguồn gốc ngẫu nhiên cố định để làm cho các ví dụ được tạo có thể dự đoán được. Thí dụ

    def add_values[arr]:
        """
        Add the values in ``arr``.
    
        This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.
    
        Some sections are omitted here for simplicity.
        """
        return sum[arr]
    
    9

  • Nếu bạn có một đoạn mã bao gồm nhiều dòng, bạn cần sử dụng '…' trên các dòng tiếp theo

    def func[]:
    
        """Some function.
    
        With several mistakes in the docstring.
    
        It has a blank like after the signature ``def func[]:``.
    
        The text 'Some function' should go in the line after the
        opening quotes of the docstring, not in the same line.
    
        There is a blank line between the docstring and the first line
        of code ``foo = 1``.
    
        The closing quotes should be in the next line, not in this one."""
    
        foo = 1
        bar = 2
        return foo + bar
    
    0

  • Nếu bạn muốn hiển thị một trường hợp ngoại lệ được nêu ra, bạn có thể làm

    def func[]:
    
        """Some function.
    
        With several mistakes in the docstring.
    
        It has a blank like after the signature ``def func[]:``.
    
        The text 'Some function' should go in the line after the
        opening quotes of the docstring, not in the same line.
    
        There is a blank line between the docstring and the first line
        of code ``foo = 1``.
    
        The closing quotes should be in the next line, not in this one."""
    
        foo = 1
        bar = 2
        return foo + bar
    
    1

    Điều cần thiết là bao gồm “Traceback [lần gọi gần đây nhất]. ”, nhưng đối với lỗi thực tế thì chỉ tên lỗi là đủ

  • Nếu có một phần nhỏ của kết quả có thể thay đổi [e. g. một hàm băm trong biểu diễn đối tượng], bạn có thể sử dụng

    class Series:
        def plot[self, kind, color='blue', **kwargs]:
            """
            Generate a plot.
    
            Render the data in the Series as a matplotlib plot of the
            specified kind.
    
            Parameters
            ----------
            kind : str
                Kind of matplotlib plot.
            color : str, default 'blue'
                Color name or rgb code.
            **kwargs
                These parameters will be passed to the matplotlib plotting
                function.
            """
            pass
    
    1 để biểu diễn phần này

    Nếu bạn muốn chỉ ra rằng

    def add_values[arr]:
        """
        Add the values in ``arr``.
    
        This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.
    
        Some sections are omitted here for simplicity.
        """
        return sum[arr]
    
    19 trả về một đối tượng AxesSubplot matplotlib, thì điều này sẽ thất bại trong doctest

    def func[]:
    
        """Some function.
    
        With several mistakes in the docstring.
    
        It has a blank like after the signature ``def func[]:``.
    
        The text 'Some function' should go in the line after the
        opening quotes of the docstring, not in the same line.
    
        There is a blank line between the docstring and the first line
        of code ``foo = 1``.
    
        The closing quotes should be in the next line, not in this one."""
    
        foo = 1
        bar = 2
        return foo + bar
    
    2

    Tuy nhiên, bạn có thể làm được [chú ý phần chú thích cần bổ sung]

    def func[]:
    
        """Some function.
    
        With several mistakes in the docstring.
    
        It has a blank like after the signature ``def func[]:``.
    
        The text 'Some function' should go in the line after the
        opening quotes of the docstring, not in the same line.
    
        There is a blank line between the docstring and the first line
        of code ``foo = 1``.
    
        The closing quotes should be in the next line, not in this one."""
    
        foo = 1
        bar = 2
        return foo + bar
    
    3

Lô trong ví dụ

Có một số phương pháp trong gấu trúc trả về lô. Để hiển thị các ô được tạo bởi các ví dụ trong tài liệu, tồn tại chỉ thị

def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
20

Để sử dụng nó, hãy đặt mã tiếp theo sau tiêu đề “Ví dụ” như hình bên dưới. Cốt truyện sẽ được tạo tự động khi xây dựng tài liệu

def func[]:

    """Some function.

    With several mistakes in the docstring.

    It has a blank like after the signature ``def func[]:``.

    The text 'Some function' should go in the line after the
    opening quotes of the docstring, not in the same line.

    There is a blank line between the docstring and the first line
    of code ``foo = 1``.

    The closing quotes should be in the next line, not in this one."""

    foo = 1
    bar = 2
    return foo + bar
4

Chia sẻ tài liệu

gấu trúc có một hệ thống chia sẻ tài liệu, với các biến thể nhỏ, giữa các lớp. Điều này giúp chúng tôi giữ cho các chuỗi tài liệu nhất quán, đồng thời giữ mọi thứ rõ ràng cho người dùng đọc. Nó phải trả giá bằng một số phức tạp khi viết

Mỗi chuỗi tài liệu được chia sẻ sẽ có một mẫu cơ sở với các biến, chẳng hạn như

def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
21. Các biến được điền sau này bằng cách sử dụng trình trang trí
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
22. Cuối cùng, các chuỗi tài liệu cũng có thể được thêm vào với trình trang trí
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
22

Trong ví dụ này, chúng tôi sẽ tạo một chuỗi tài liệu gốc bình thường [điều này giống như

def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
24. Sau đó, chúng tôi sẽ có hai con [như
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
25 và
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
26]. Chúng tôi sẽ thay thế tên lớp trong chuỗi tài liệu này

def func[]:

    """Some function.

    With several mistakes in the docstring.

    It has a blank like after the signature ``def func[]:``.

    The text 'Some function' should go in the line after the
    opening quotes of the docstring, not in the same line.

    There is a blank line between the docstring and the first line
    of code ``foo = 1``.

    The closing quotes should be in the next line, not in this one."""

    foo = 1
    bar = 2
    return foo + bar
5

Các docstrings kết quả là

def func[]:

    """Some function.

    With several mistakes in the docstring.

    It has a blank like after the signature ``def func[]:``.

    The text 'Some function' should go in the line after the
    opening quotes of the docstring, not in the same line.

    There is a blank line between the docstring and the first line
    of code ``foo = 1``.

    The closing quotes should be in the next line, not in this one."""

    foo = 1
    bar = 2
    return foo + bar
6

Lưu ý

  1. Chúng tôi "nối" chuỗi tài liệu gốc vào chuỗi tài liệu con, ban đầu trống

Các tệp của chúng tôi thường chứa một giá trị thay thế cấp mô-đun

def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
27 với một số giá trị thay thế phổ biến [chẳng hạn như
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
28,
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
29, v.v.]

Bạn có thể thay thế và thêm vào trong một lần chụp bằng thứ gì đó như

def func[]:

    """Some function.

    With several mistakes in the docstring.

    It has a blank like after the signature ``def func[]:``.

    The text 'Some function' should go in the line after the
    opening quotes of the docstring, not in the same line.

    There is a blank line between the docstring and the first line
    of code ``foo = 1``.

    The closing quotes should be in the next line, not in this one."""

    foo = 1
    bar = 2
    return foo + bar
7

trong đó

def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
30 có thể đến từ tên chức năng ánh xạ từ điển cấp mô-đun
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
31 tới chuỗi tài liệu. Bất cứ khi nào có thể, chúng tôi thích sử dụng
def add_values[arr]:
    """
    Add the values in ``arr``.

    This is equivalent to Python ``sum`` of :meth:`pandas.Series.sum`.

    Some sections are omitted here for simplicity.
    """
    return sum[arr]
22 hơn, vì quy trình viết chuỗi tài liệu gần với bình thường hơn một chút

Chủ Đề