From aa0804fdf378c29690312a9449089da053d3208e Mon Sep 17 00:00:00 2001 From: AnandMukherjee2004 Date: Tue, 16 Sep 2025 00:22:54 +0530 Subject: [PATCH 01/11] DOC: Clarify parentheses vs. brackets usage (GH#62314) --- doc/source/getting_started/index.rst | 43 +++++ .../11_brackets_vs_parenthesis.rst | 151 ++++++++++++++++++ .../getting_started/intro_tutorials/index.rst | 1 + package-lock.json | 6 + 4 files changed, 201 insertions(+) create mode 100644 doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst create mode 100644 package-lock.json diff --git a/doc/source/getting_started/index.rst b/doc/source/getting_started/index.rst index a17699a71fbd3..d72c27929a25f 100644 --- a/doc/source/getting_started/index.rst +++ b/doc/source/getting_started/index.rst @@ -520,6 +520,49 @@ Data sets often contain more than just numerical data. pandas provides a wide ra :ref:`To user guide ` +.. raw:: html + + + + + + + +
+ +
+
+ +Understanding the difference between parentheses and square brackets is crucial for pandas users. Parentheses are used for function calls and grouping, while square brackets are for indexing and selection. + +.. raw:: html + +
+ + +:ref:`To introduction tutorial <10min_tut_11_brackets_vs_parenthesis>` + +.. raw:: html + + + + +:ref:`To user guide ` + .. raw:: html diff --git a/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst b/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst new file mode 100644 index 0000000000000..208550ef20a9d --- /dev/null +++ b/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst @@ -0,0 +1,151 @@ +.. _10min_tut_11_brackets_vs_parenthesis: + +Parentheses vs. Square Brackets in Python and pandas +==================================================== + +Python and pandas use both **parentheses** ``()`` and **square brackets** ``[]``, but these have separate and important roles. Understanding their differences is essential for writing correct Python and pandas code. + +Overview of Bracket Usage +------------------------- + ++------------------------------------+-------------------------------+------------------------------+ +| Context | Parentheses ``()`` | Square Brackets ``[]`` | ++====================================+===============================+==============================+ +| Function and method calls | Yes: ``df.mean()`` | No | ++------------------------------------+-------------------------------+------------------------------+ +| Tuple creation | Yes: ``(a, b, c)`` | No | ++------------------------------------+-------------------------------+------------------------------+ +| List creation and item access | No | Yes: ``a[0]``, ``[1, 2]`` | ++------------------------------------+-------------------------------+------------------------------+ +| Dictionary item access | No | Yes: ``mydict['key']`` | ++------------------------------------+-------------------------------+------------------------------+ +| pandas column selection | No | Yes: ``df['A']``, | +| | | ``df[['A', 'B']]`` | ++------------------------------------+-------------------------------+------------------------------+ +| pandas row selection and slicing | No | Yes: ``df[0:5]``, | +| | | ``df.loc[2]`` | ++------------------------------------+-------------------------------+------------------------------+ +| Boolean indexing | No | Yes: ``df[df['col'] > 10]`` | ++------------------------------------+-------------------------------+------------------------------+ +| Grouping/logical expressions | Yes: ``(x + y) * z`` | No | ++------------------------------------+-------------------------------+------------------------------+ + +Detailed Explanations and Examples +---------------------------------- + +**Parentheses ``()``** + +- Used to *call* functions and methods, enclosing arguments: + .. code-block:: python + + df.mean() + print("Hello, world!") + sum([1, 2, 3]) + +- Used to create *tuples*, which are immutable ordered collections: + .. code-block:: python + + coordinates = (10, 20) + empty_tuple = () + +- Used for *grouping expressions* in mathematics and logic: + .. code-block:: python + + result = (1 + 2) * 3 + is_valid = (score > 0) and (score < 100) + +- Used to spread Python statements over multiple lines: + + .. code-block:: python + + total = ( + 1 + + 2 + + 3 + ) + +**Square Brackets ``[]``** + +- Used to *define* and *access* elements of Python lists: + .. code-block:: python + + numbers = [1, 2, 3, 4] + first = numbers[0] + sub = numbers[1:3] + +- Used to *access* values in dictionaries by key: + .. code-block:: python + + prices = {'apple': 40, 'banana': 10} + apple_price = prices['apple'] + +- Used for all kinds of *indexing* and *selection* in pandas DataFrames and Series: + + *Single column selection* (returns Series): + .. code-block:: python + + df['A'] + + *Multiple columns selection* (returns DataFrame): + .. code-block:: python + + df[['A', 'B']] + + Here, the inner brackets create a Python list of column labels, and the outer brackets are pandas selection syntax. + + *Row selection and slicing*: + .. code-block:: python + + df[0:2] # selects rows 0 and 1 by integer position + df.loc[2] # selects row with label/index 2 + df.iloc[2] # selects row at integer position 2 + + *Boolean indexing (row filtering)*: + .. code-block:: python + + df[df['A'] > 5] # returns only rows where column 'A' is greater than 5 + +Key Points to Remember +---------------------- + +- **Parentheses** are for function/method calls, tuple creation, grouping, and continuation of statements. +- **Square brackets** are for creating and accessing lists, dictionary values, slicing sequences, and—critically for pandas—selecting/subsetting columns and rows. +- In pandas, *single* square brackets select a single column as a Series (``df['A']``), while *double* square brackets select multiple columns as a DataFrame (``df[['A', 'B']]``) because the *inner brackets create a Python list* of column labels. +- Boolean indexing in pandas always uses square brackets enclosing a boolean Series: ``df[df['A'] > 5]``. + +Common Pitfalls +--------------- + +- Attempting to use parentheses for list/tensor/column access or slicing will result in errors. +- Using single brackets with a list inside (like ``df[['A']]``) still returns a DataFrame, not a Series—bracket count and the type of object inside matters. +- Remember that method calls (like ``df.mean()`` or ``df.groupby('A')``) always require parentheses, even if there are no arguments. + +Example Summary +--------------- + +.. code-block:: python + + import pandas as pd + df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}) + + # Function and method calls + df.mean() + + # Tuple creation + t = (1, 2, 3) + + # List creation/access + mylist = [10, 20, 30] + first_item = mylist[0] + + # pandas column selection + df['A'] + df[['A', 'B']] + + # pandas boolean indexing + df[df['B'] > 4] + + # Grouping/logical expressions + selected = (df['A'] > 1) & (df['B'] < 6) + +Getting comfortable with the distinction between parentheses and square brackets is a major milestone for every new pandas user. This understanding leads to correct code and enhanced productivity when working in both core Python and pandas. diff --git a/doc/source/getting_started/intro_tutorials/index.rst b/doc/source/getting_started/intro_tutorials/index.rst index c67e18043c175..4968908366359 100644 --- a/doc/source/getting_started/intro_tutorials/index.rst +++ b/doc/source/getting_started/intro_tutorials/index.rst @@ -19,3 +19,4 @@ Getting started tutorials 08_combine_dataframes 09_timeseries 10_text_data + 11_brackets_vs_parenthesis diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000000000..bb3c8e31ba2f5 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "pandas", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} From ada92d728bab01fdb2300922bc7ac0b34130e711 Mon Sep 17 00:00:00 2001 From: AnandMukherjee2004 Date: Tue, 16 Sep 2025 22:10:58 +0530 Subject: [PATCH 02/11] DOC: Clarify parentheses vs. brackets usage (GH#62314) updated --- .../11_brackets_vs_parenthesis.rst | 147 +----------------- 1 file changed, 1 insertion(+), 146 deletions(-) diff --git a/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst b/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst index 208550ef20a9d..2ec6d804406b0 100644 --- a/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst +++ b/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst @@ -3,149 +3,4 @@ Parentheses vs. Square Brackets in Python and pandas ==================================================== -Python and pandas use both **parentheses** ``()`` and **square brackets** ``[]``, but these have separate and important roles. Understanding their differences is essential for writing correct Python and pandas code. - -Overview of Bracket Usage -------------------------- - -+------------------------------------+-------------------------------+------------------------------+ -| Context | Parentheses ``()`` | Square Brackets ``[]`` | -+====================================+===============================+==============================+ -| Function and method calls | Yes: ``df.mean()`` | No | -+------------------------------------+-------------------------------+------------------------------+ -| Tuple creation | Yes: ``(a, b, c)`` | No | -+------------------------------------+-------------------------------+------------------------------+ -| List creation and item access | No | Yes: ``a[0]``, ``[1, 2]`` | -+------------------------------------+-------------------------------+------------------------------+ -| Dictionary item access | No | Yes: ``mydict['key']`` | -+------------------------------------+-------------------------------+------------------------------+ -| pandas column selection | No | Yes: ``df['A']``, | -| | | ``df[['A', 'B']]`` | -+------------------------------------+-------------------------------+------------------------------+ -| pandas row selection and slicing | No | Yes: ``df[0:5]``, | -| | | ``df.loc[2]`` | -+------------------------------------+-------------------------------+------------------------------+ -| Boolean indexing | No | Yes: ``df[df['col'] > 10]`` | -+------------------------------------+-------------------------------+------------------------------+ -| Grouping/logical expressions | Yes: ``(x + y) * z`` | No | -+------------------------------------+-------------------------------+------------------------------+ - -Detailed Explanations and Examples ----------------------------------- - -**Parentheses ``()``** - -- Used to *call* functions and methods, enclosing arguments: - .. code-block:: python - - df.mean() - print("Hello, world!") - sum([1, 2, 3]) - -- Used to create *tuples*, which are immutable ordered collections: - .. code-block:: python - - coordinates = (10, 20) - empty_tuple = () - -- Used for *grouping expressions* in mathematics and logic: - .. code-block:: python - - result = (1 + 2) * 3 - is_valid = (score > 0) and (score < 100) - -- Used to spread Python statements over multiple lines: - - .. code-block:: python - - total = ( - 1 + - 2 + - 3 - ) - -**Square Brackets ``[]``** - -- Used to *define* and *access* elements of Python lists: - .. code-block:: python - - numbers = [1, 2, 3, 4] - first = numbers[0] - sub = numbers[1:3] - -- Used to *access* values in dictionaries by key: - .. code-block:: python - - prices = {'apple': 40, 'banana': 10} - apple_price = prices['apple'] - -- Used for all kinds of *indexing* and *selection* in pandas DataFrames and Series: - - *Single column selection* (returns Series): - .. code-block:: python - - df['A'] - - *Multiple columns selection* (returns DataFrame): - .. code-block:: python - - df[['A', 'B']] - - Here, the inner brackets create a Python list of column labels, and the outer brackets are pandas selection syntax. - - *Row selection and slicing*: - .. code-block:: python - - df[0:2] # selects rows 0 and 1 by integer position - df.loc[2] # selects row with label/index 2 - df.iloc[2] # selects row at integer position 2 - - *Boolean indexing (row filtering)*: - .. code-block:: python - - df[df['A'] > 5] # returns only rows where column 'A' is greater than 5 - -Key Points to Remember ----------------------- - -- **Parentheses** are for function/method calls, tuple creation, grouping, and continuation of statements. -- **Square brackets** are for creating and accessing lists, dictionary values, slicing sequences, and—critically for pandas—selecting/subsetting columns and rows. -- In pandas, *single* square brackets select a single column as a Series (``df['A']``), while *double* square brackets select multiple columns as a DataFrame (``df[['A', 'B']]``) because the *inner brackets create a Python list* of column labels. -- Boolean indexing in pandas always uses square brackets enclosing a boolean Series: ``df[df['A'] > 5]``. - -Common Pitfalls ---------------- - -- Attempting to use parentheses for list/tensor/column access or slicing will result in errors. -- Using single brackets with a list inside (like ``df[['A']]``) still returns a DataFrame, not a Series—bracket count and the type of object inside matters. -- Remember that method calls (like ``df.mean()`` or ``df.groupby('A')``) always require parentheses, even if there are no arguments. - -Example Summary ---------------- - -.. code-block:: python - - import pandas as pd - df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}) - - # Function and method calls - df.mean() - - # Tuple creation - t = (1, 2, 3) - - # List creation/access - mylist = [10, 20, 30] - first_item = mylist[0] - - # pandas column selection - df['A'] - df[['A', 'B']] - - # pandas boolean indexing - df[df['B'] > 4] - - # Grouping/logical expressions - selected = (df['A'] > 1) & (df['B'] < 6) - -Getting comfortable with the distinction between parentheses and square brackets is a major milestone for every new pandas user. This understanding leads to correct code and enhanced productivity when working in both core Python and pandas. +In Python and pandas, parentheses ``()`` and square brackets ``[]`` have distinct uses, which can sometimes be confusing for new users. Parentheses are used to call functions and methods (for example, ``df.mean()``), to group expressions in calculations (such as ``(a + b) * c``), and to create tuples. Square brackets, on the other hand, are used for defining lists and for indexing or selecting data—in both core Python and pandas. For example, ``df['A']`` selects column ``A`` from a DataFrame, and ``df[0:3]`` selects rows by position. In pandas, square brackets are always used when you want to select or filter data, while parentheses are used any time you are calling a method or function. Remember: use ``[]`` for selection or indexing, and ``()`` for function calls and grouping. From 41272b95f727eff306462db68c32d775ff7df307 Mon Sep 17 00:00:00 2001 From: AnandMukherjee2004 Date: Tue, 16 Sep 2025 22:13:44 +0530 Subject: [PATCH 03/11] DOC: Clarify parentheses vs. brackets usage (GH#62314) updated --- .../intro_tutorials/11_brackets_vs_parenthesis.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst b/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst index 2ec6d804406b0..c89e132c3c3a9 100644 --- a/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst +++ b/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst @@ -1,6 +1,7 @@ -.. _10min_tut_11_brackets_vs_parenthesis: +In both Python and pandas, it’s important to understand the difference between parentheses ``()`` and square brackets ``[]``: -Parentheses vs. Square Brackets in Python and pandas -==================================================== +- **Parentheses** are used to call functions and methods. For example, ``df.mean()`` calculates the mean of a DataFrame, and parentheses are also used to group expressions, such as ``(a + b) * c``, or to create tuples: ``(1, 2, 3)``. +- **Square brackets** are used for indexing, selecting data, and defining lists. In pandas, you use square brackets to select columns or filter data—for instance, ``df['A']`` selects column ``A``, while ``df[0:3]`` selects rows by position. In standard Python, square brackets are also used to define a list, as in ``my_list = [1, 2, 3]``. -In Python and pandas, parentheses ``()`` and square brackets ``[]`` have distinct uses, which can sometimes be confusing for new users. Parentheses are used to call functions and methods (for example, ``df.mean()``), to group expressions in calculations (such as ``(a + b) * c``), and to create tuples. Square brackets, on the other hand, are used for defining lists and for indexing or selecting data—in both core Python and pandas. For example, ``df['A']`` selects column ``A`` from a DataFrame, and ``df[0:3]`` selects rows by position. In pandas, square brackets are always used when you want to select or filter data, while parentheses are used any time you are calling a method or function. Remember: use ``[]`` for selection or indexing, and ``()`` for function calls and grouping. +Remember: +**Use [] for selection or indexing, and () for calling functions or grouping expressions.** From 8c77d05b87c9b6593cdf171e119d0dc74bccb461 Mon Sep 17 00:00:00 2001 From: AnandMukherjee2004 Date: Tue, 16 Sep 2025 22:22:19 +0530 Subject: [PATCH 04/11] DOC: Clarify parentheses vs. brackets usage (GH#62314) updated --- .../intro_tutorials/11_brackets_vs_parenthesis.rst | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst b/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst index c89e132c3c3a9..b361a32775d49 100644 --- a/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst +++ b/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst @@ -1,7 +1,15 @@ -In both Python and pandas, it’s important to understand the difference between parentheses ``()`` and square brackets ``[]``: +.. _10min_tut_11_brackets_vs_parenthesis: + +Parentheses vs. Square Brackets in Python and pandas +==================================================== + +In both Python and pandas, it’s important to understand the difference between parentheses (``()``) and square brackets (``[]``): - **Parentheses** are used to call functions and methods. For example, ``df.mean()`` calculates the mean of a DataFrame, and parentheses are also used to group expressions, such as ``(a + b) * c``, or to create tuples: ``(1, 2, 3)``. - **Square brackets** are used for indexing, selecting data, and defining lists. In pandas, you use square brackets to select columns or filter data—for instance, ``df['A']`` selects column ``A``, while ``df[0:3]`` selects rows by position. In standard Python, square brackets are also used to define a list, as in ``my_list = [1, 2, 3]``. Remember: -**Use [] for selection or indexing, and () for calling functions or grouping expressions.** +**Use ``[]`` for selection or indexing, and ``()`` for calling functions or grouping expressions.** + +For more explanation, see `Brackets in Python and pandas `__. + From fac8e7c521e48d9c714420b7c44d4d31b27f2655 Mon Sep 17 00:00:00 2001 From: AnandMukherjee2004 Date: Tue, 16 Sep 2025 22:27:48 +0530 Subject: [PATCH 05/11] DOC: Clarify parentheses vs. brackets usage (GH#62314) updated --- .../intro_tutorials/11_brackets_vs_parenthesis.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst b/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst index b361a32775d49..73bc3b5aa2a57 100644 --- a/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst +++ b/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst @@ -3,13 +3,13 @@ Parentheses vs. Square Brackets in Python and pandas ==================================================== -In both Python and pandas, it’s important to understand the difference between parentheses (``()``) and square brackets (``[]``): +In both Python and pandas, it’s important to understand the difference between parentheses ``()`` and square brackets ``[]``: - **Parentheses** are used to call functions and methods. For example, ``df.mean()`` calculates the mean of a DataFrame, and parentheses are also used to group expressions, such as ``(a + b) * c``, or to create tuples: ``(1, 2, 3)``. - **Square brackets** are used for indexing, selecting data, and defining lists. In pandas, you use square brackets to select columns or filter data—for instance, ``df['A']`` selects column ``A``, while ``df[0:3]`` selects rows by position. In standard Python, square brackets are also used to define a list, as in ``my_list = [1, 2, 3]``. Remember: -**Use ``[]`` for selection or indexing, and ``()`` for calling functions or grouping expressions.** +**Use [] for selection or indexing, and () for calling functions or grouping expressions.** For more explanation, see `Brackets in Python and pandas `__. From 689b069bc80a6b4dc85c8a9db1eb86c072c133e0 Mon Sep 17 00:00:00 2001 From: AnandMukherjee2004 Date: Tue, 16 Sep 2025 22:34:36 +0530 Subject: [PATCH 06/11] DOC: Fix trailing whitespace and end-of-file issues (pre-commit CI) --- .../intro_tutorials/11_brackets_vs_parenthesis.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst b/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst index 73bc3b5aa2a57..da0874098a0a9 100644 --- a/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst +++ b/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst @@ -2,7 +2,6 @@ Parentheses vs. Square Brackets in Python and pandas ==================================================== - In both Python and pandas, it’s important to understand the difference between parentheses ``()`` and square brackets ``[]``: - **Parentheses** are used to call functions and methods. For example, ``df.mean()`` calculates the mean of a DataFrame, and parentheses are also used to group expressions, such as ``(a + b) * c``, or to create tuples: ``(1, 2, 3)``. @@ -11,5 +10,4 @@ In both Python and pandas, it’s important to understand the difference between Remember: **Use [] for selection or indexing, and () for calling functions or grouping expressions.** -For more explanation, see `Brackets in Python and pandas `__. - +For more explanation, see `Brackets in Python and pandas `__. \ No newline at end of file From a1feaabad38c852732e219f43894c0e7c1fb8306 Mon Sep 17 00:00:00 2001 From: AnandMukherjee2004 Date: Tue, 16 Sep 2025 23:03:06 +0530 Subject: [PATCH 07/11] DOC: Fix trailing whitespace and end-of-file issues (pre-commit CI) --- .../intro_tutorials/11_brackets_vs_parenthesis.rst | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst b/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst index da0874098a0a9..f751165c57cb6 100644 --- a/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst +++ b/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst @@ -2,12 +2,14 @@ Parentheses vs. Square Brackets in Python and pandas ==================================================== -In both Python and pandas, it’s important to understand the difference between parentheses ``()`` and square brackets ``[]``: -- **Parentheses** are used to call functions and methods. For example, ``df.mean()`` calculates the mean of a DataFrame, and parentheses are also used to group expressions, such as ``(a + b) * c``, or to create tuples: ``(1, 2, 3)``. +In both Python and pandas, it is important to understand the difference between parentheses ``()`` and square brackets ``[]``: + +- **Parentheses** are used to call functions and methods. For example, ``df.mean()`` calculates the mean of a DataFrame. Parentheses are also used to group expressions, such as ``(a + b) * c``, or to create tuples: ``(1, 2, 3)``. - **Square brackets** are used for indexing, selecting data, and defining lists. In pandas, you use square brackets to select columns or filter data—for instance, ``df['A']`` selects column ``A``, while ``df[0:3]`` selects rows by position. In standard Python, square brackets are also used to define a list, as in ``my_list = [1, 2, 3]``. -Remember: -**Use [] for selection or indexing, and () for calling functions or grouping expressions.** -For more explanation, see `Brackets in Python and pandas `__. \ No newline at end of file +**Remember :** +Use ``[]`` for selection or indexing, and ``()`` for calling functions or grouping expressions. + +For more explanation, see `Brackets in Python and pandas `__. From 2c658b182634d3af7a8e25feb92dad48b2c0122e Mon Sep 17 00:00:00 2001 From: AnandMukherjee2004 Date: Tue, 16 Sep 2025 23:15:22 +0530 Subject: [PATCH 08/11] DOC: Fix trailing whitespace and end-of-file issues (pre-commit CI) --- .../11_brackets_vs_parenthesis.rst | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst b/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst index f751165c57cb6..b32d2b152bc65 100644 --- a/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst +++ b/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst @@ -1,15 +1 @@ -.. _10min_tut_11_brackets_vs_parenthesis: - -Parentheses vs. Square Brackets in Python and pandas -==================================================== - -In both Python and pandas, it is important to understand the difference between parentheses ``()`` and square brackets ``[]``: - -- **Parentheses** are used to call functions and methods. For example, ``df.mean()`` calculates the mean of a DataFrame. Parentheses are also used to group expressions, such as ``(a + b) * c``, or to create tuples: ``(1, 2, 3)``. -- **Square brackets** are used for indexing, selecting data, and defining lists. In pandas, you use square brackets to select columns or filter data—for instance, ``df['A']`` selects column ``A``, while ``df[0:3]`` selects rows by position. In standard Python, square brackets are also used to define a list, as in ``my_list = [1, 2, 3]``. - - -**Remember :** -Use ``[]`` for selection or indexing, and ``()`` for calling functions or grouping expressions. - -For more explanation, see `Brackets in Python and pandas `__. +.. _10min_tut_11_brackets_vs_parenthesis:\n\nParentheses vs. Square Brackets in Python and pandas\n====================================================\n\nIn both Python and pandas, it is important to understand the difference between parentheses ``()`` and square brackets ``[]``:\n\n- **Parentheses** are used to call functions and methods. For example, ``df.mean()`` calculates the mean of a DataFrame. Parentheses are also used to group expressions, such as ``(a + b) * c``, or to create tuples: ``(1, 2, 3)``.\n- **Square brackets** are used for indexing, selecting data, and defining lists. In pandas, you use square brackets to select columns or filter data—for instance, ``df['A']`` selects column ``A``, while ``df[0:3]`` selects rows by position. In standard Python, square brackets are also used to define a list, as in ``my_list = [1, 2, 3]``.\n\n\n**Remember :**\nUse ``[]`` for selection or indexing, and ``()`` for calling functions or grouping expressions.\n\nFor more explanation, see `Brackets in Python and pandas `__.\n \ No newline at end of file From cf1e39505bb90a7f63ddeb436f189c453ea8b061 Mon Sep 17 00:00:00 2001 From: AnandMukherjee2004 Date: Tue, 16 Sep 2025 23:19:14 +0530 Subject: [PATCH 09/11] DOC: Fix trailing whitespace and end-of-file issues (pre-commit CI) --- .../intro_tutorials/11_brackets_vs_parenthesis.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst b/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst index b32d2b152bc65..55fb909e647f0 100644 --- a/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst +++ b/doc/source/getting_started/intro_tutorials/11_brackets_vs_parenthesis.rst @@ -1 +1,13 @@ -.. _10min_tut_11_brackets_vs_parenthesis:\n\nParentheses vs. Square Brackets in Python and pandas\n====================================================\n\nIn both Python and pandas, it is important to understand the difference between parentheses ``()`` and square brackets ``[]``:\n\n- **Parentheses** are used to call functions and methods. For example, ``df.mean()`` calculates the mean of a DataFrame. Parentheses are also used to group expressions, such as ``(a + b) * c``, or to create tuples: ``(1, 2, 3)``.\n- **Square brackets** are used for indexing, selecting data, and defining lists. In pandas, you use square brackets to select columns or filter data—for instance, ``df['A']`` selects column ``A``, while ``df[0:3]`` selects rows by position. In standard Python, square brackets are also used to define a list, as in ``my_list = [1, 2, 3]``.\n\n\n**Remember :**\nUse ``[]`` for selection or indexing, and ``()`` for calling functions or grouping expressions.\n\nFor more explanation, see `Brackets in Python and pandas `__.\n \ No newline at end of file +.. _10min_tut_11_brackets_vs_parenthesis: + +Parentheses vs. Square Brackets in Python and pandas +==================================================== + +In both Python and pandas, it is important to understand the difference between parentheses ``()`` and square brackets ``[]``: + +- **Parentheses** are used to call functions and methods. For example, ``df.mean()`` calculates the mean of a DataFrame. Parentheses are also used to group expressions, such as ``(a + b) * c``, or to create tuples: ``(1, 2, 3)``. +- **Square brackets** are used for indexing, selecting data, and defining lists. In pandas, you use square brackets to select columns or filter data—for instance, ``df['A']`` selects column ``A``, while ``df[0:3]`` selects rows by position. In standard Python, square brackets are also used to define a list, as in ``my_list = [1, 2, 3]``. + +Remember: Use ``[]`` for selection or indexing, and ``()`` for calling functions or grouping expressions. + +For more explanation, see `Brackets in Python and pandas `__. From 853773687e2f2946604d9674125493cc5f62c630 Mon Sep 17 00:00:00 2001 From: AnandMukherjee2004 Date: Wed, 17 Sep 2025 16:54:41 +0530 Subject: [PATCH 10/11] DOC: expand data table diagram and add explanation of indexes to tutorial (#62358) --- .../getting_started/intro_tutorials/01_table_oriented.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/getting_started/intro_tutorials/01_table_oriented.rst b/doc/source/getting_started/intro_tutorials/01_table_oriented.rst index 7e86ad6c499d9..d4504df20948a 100644 --- a/doc/source/getting_started/intro_tutorials/01_table_oriented.rst +++ b/doc/source/getting_started/intro_tutorials/01_table_oriented.rst @@ -29,7 +29,7 @@ documentation. pandas data table representation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. image:: ../../_static/schemas/01_table_dataframe.svg +.. image:: ../../_static/schemas/01_dataframe.svg :align: center .. raw:: html From 2399a2e53dbfca6cecaa2756cd8b2931f75f50dc Mon Sep 17 00:00:00 2001 From: AnandMukherjee2004 Date: Wed, 17 Sep 2025 17:56:50 +0530 Subject: [PATCH 11/11] DOC: expand data table diagram and add explanation of indexes to tutorial (#62358) --- doc/source/_static/schemas/01_dataframe.svg | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/source/_static/schemas/01_dataframe.svg diff --git a/doc/source/_static/schemas/01_dataframe.svg b/doc/source/_static/schemas/01_dataframe.svg new file mode 100644 index 0000000000000..49f9fc426e84a --- /dev/null +++ b/doc/source/_static/schemas/01_dataframe.svg @@ -0,0 +1 @@ + \ No newline at end of file