Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/getting_started/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -669,3 +669,5 @@ material is enlisted in the community contributed :ref:`communitytutorials`.
intro_tutorials/index
comparison/index
tutorials
parentheses_vs_brackets

41 changes: 41 additions & 0 deletions doc/source/getting_started/parentheses_vs_brackets.rst
Original file line number Diff line number Diff line change
@@ -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()
Loading