From 440dde68ca590ed1b167fe0349cb096b18bf35bc Mon Sep 17 00:00:00 2001 From: Disney Gandikoda Date: Wed, 17 Sep 2025 13:49:43 +0100 Subject: [PATCH 1/2] DOC: Add section clarifying parentheses vs. brackets usage --- doc/source/getting_started/index.rst | 2 + .../parentheses_vs_brackets.rst | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 doc/source/getting_started/parentheses_vs_brackets.rst diff --git a/doc/source/getting_started/index.rst b/doc/source/getting_started/index.rst index a17699a71fbd3..08815fd23cd63 100644 --- a/doc/source/getting_started/index.rst +++ b/doc/source/getting_started/index.rst @@ -669,3 +669,5 @@ material is enlisted in the community contributed :ref:`communitytutorials`. intro_tutorials/index comparison/index tutorials + parentheses_vs_brackets + diff --git a/doc/source/getting_started/parentheses_vs_brackets.rst b/doc/source/getting_started/parentheses_vs_brackets.rst new file mode 100644 index 0000000000000..dde12cc0bae2e --- /dev/null +++ b/doc/source/getting_started/parentheses_vs_brackets.rst @@ -0,0 +1,41 @@ +Parentheses vs. Brackets in pandas +================================== + +In pandas, beginners often get confused between **parentheses `()`** and **square brackets `[]`**. +Understanding the difference is essential for using pandas effectively. + +**Parentheses `()`** are used to **call functions or methods**: + +.. code-block:: python + + import pandas as pd + df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}) + + # Call the head() method to see first 5 rows + df.head() + +**Square brackets `[]`** are used to **access data or select columns**: + +.. code-block:: python + + # Select a single column as a Series + df['A'] + + # Select multiple columns as a DataFrame + df[['A', 'B']] + +**Key points:** + +- `()` always executes something (a function/method). +- `[]` always retrieves data (like indexing or slicing). +- Mixing them up is a common source of errors for new pandas users. + +**Additional examples:** + +.. code-block:: python + + # Using brackets to filter rows + df[df['A'] > 1] + + # Using parentheses to chain method calls + df[['A', 'B']].head() From 13ffa1a54e8af8fe7d5fa236b72e5fa279f9b031 Mon Sep 17 00:00:00 2001 From: Disney Gandikoda Date: Wed, 17 Sep 2025 14:07:22 +0100 Subject: [PATCH 2/2] DOC: Fix trailing whitespace, end-of-file, and sphinx-lint issues --- doc/source/getting_started/parentheses_vs_brackets.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/source/getting_started/parentheses_vs_brackets.rst b/doc/source/getting_started/parentheses_vs_brackets.rst index dde12cc0bae2e..835cd79a511eb 100644 --- a/doc/source/getting_started/parentheses_vs_brackets.rst +++ b/doc/source/getting_started/parentheses_vs_brackets.rst @@ -1,10 +1,10 @@ Parentheses vs. Brackets in pandas ================================== -In pandas, beginners often get confused between **parentheses `()`** and **square brackets `[]`**. +In pandas, beginners often get confused between **parentheses ``()``** and **square brackets ``[]``**. Understanding the difference is essential for using pandas effectively. -**Parentheses `()`** are used to **call functions or methods**: +**Parentheses ``()``** are used to **call functions or methods**: .. code-block:: python @@ -14,7 +14,7 @@ Understanding the difference is essential for using pandas effectively. # Call the head() method to see first 5 rows df.head() -**Square brackets `[]`** are used to **access data or select columns**: +**Square brackets ``[]``** are used to **access data or select columns**: .. code-block:: python @@ -26,8 +26,8 @@ Understanding the difference is essential for using pandas effectively. **Key points:** -- `()` always executes something (a function/method). -- `[]` always retrieves data (like indexing or slicing). +- `()` always executes something (a function/method). +- `[]` always retrieves data (like indexing or slicing). - Mixing them up is a common source of errors for new pandas users. **Additional examples:**