Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Term Entry] Python:Pandas built-in-functions: .concat() #4814

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
64 changes: 64 additions & 0 deletions content/pandas/concepts/built-in-functions/terms/concat/concat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
Title: '.concat()'
Description: 'Concatenates multiple Dataframes or Series along a particular axis'
Subjects: # Please only use Subjects in the subjects.md file (https://github.com/Codecademy/docs/blob/main/documentation/subjects.md). If that list feels insufficient, feel free to create a new Subject and add it to subjects.md in your PR!
- 'A subject name'
- 'A second subject name'
- 'An nth subject name'
Tags: # Please only use Tags in the tags.md file (https://github.com/Codecademy/docs/blob/main/documentation/tags.md). If that list feels insufficient, feel free to create a new Tag and add it to tags.md in your PR!
- 'Data Structures'
- 'Functions'
- 'Pandas'
- 'CSV'
- 'Data'
CatalogContent: # Please use course/path landing page slugs, rather than linking to individual content items. If listing multiple items, please put the most relevant one first
- 'learn-Data-Analysis-with-Pandas'
- 'paths/data-science'
---
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
---
Title: '.concat()'
Description: 'Concatenates multiple Dataframes or Series along a particular axis'
Subjects: # Please only use Subjects in the subjects.md file (https://github.com/Codecademy/docs/blob/main/documentation/subjects.md). If that list feels insufficient, feel free to create a new Subject and add it to subjects.md in your PR!
- 'A subject name'
- 'A second subject name'
- 'An nth subject name'
Tags: # Please only use Tags in the tags.md file (https://github.com/Codecademy/docs/blob/main/documentation/tags.md). If that list feels insufficient, feel free to create a new Tag and add it to tags.md in your PR!
- 'Data Structures'
- 'Functions'
- 'Pandas'
- 'CSV'
- 'Data'
CatalogContent: # Please use course/path landing page slugs, rather than linking to individual content items. If listing multiple items, please put the most relevant one first
- 'learn-Data-Analysis-with-Pandas'
- 'paths/data-science'
---
---
Title: '.concat()'
Description: 'Concatenates multiple DataFrames or Series along a specified axis.'
Subjects:
- 'Computer Science'
- 'Data Science'
Tags:
- 'Data Structures'
- 'Functions'
- 'Pandas'
CatalogContent:
- 'learn-python-3'
- 'paths/computer-science'
- 'paths/data-science'
- 'paths/data-science-foundations'
---

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added relevant subjects and tags from the documents


The `.concat()` function is used to concatenate and combine multiple [`DataFrames`](https://www.codecademy.com/resources/docs/pandas/dataframe) or [`Series`] along a particular axis.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `.concat()` function is used to concatenate and combine multiple [`DataFrames`](https://www.codecademy.com/resources/docs/pandas/dataframe) or [`Series`] along a particular axis.
The **`.concat()`** function is used to concatenate and combine multiple [`DataFrames`](https://www.codecademy.com/resources/docs/pandas/dataframe) or [`Series`] along a specified axis.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first instance of the term should be wrapped in bold


## Syntax

```pseudo
pandas.concat(objs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The syntax should include all the parameters from the documentation of the .concat() method. I found out the following two:

pandas.concat(objs, axis=0, join='outer', ignore_index=False, keys=None, levels=None, names=None, verify_integrity=False, sort=False, copy=True)

pandas.concat(objs, axis, join, ignore_index, keys, levels, names, verify_integrity, sort, copy)

You can use either of them

```

The `objs` parameter is essential and must be specified. It represents the objects to be concatenated and can be a sequence or mapping of pandas Series or DataFrame objects. The objects should be passed as a sequence (like a list or tuple) or a mapping (like a dictionary).

The rest of the parameters are listed below:

| Parameter Name | Data Type | Usage |
| :----------------: | :--------------------------------------------------: | -------------------------------------------------------------------------------------- |
| `axis` | int (0 for rows, 1 for columns ), default 0 | Specifies the axis along which to concatenate the objects |
| `join` | str (“outer” (default), “inner,” “left,” or “right”) | Determines how to handle indexes on other axes |
| `ignore_index` | bool, default `False` | If `True`, it resets the index in the resulting DataFrame |
| `keys` | sequence (list or tuple), default None | Lets you construct a hierarchical index using the provided keys as the outermost level |
| `levels` | list of sequences, default None | Specific levels to use for constructing a MultiIndex if keys are provided |
| `names` | list of str, default None | Names for the levels generated in the hierarchical index |
| `verify_integrity` | bool, default `False` | If `True`, checks whether the new concatenated axis contains duplicates |
| `sort` | bool, default `False` | If `True`, it sorts the resulting Series or Dataframe by the keys |
| `copy` | bool, default `True` | If `False`, it avoids copying data unnecessarily |

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the parameters need to be described in the below format:

  • objs: A sequence or mapping of Series or DataFrame objects. Can be a list of objects or a dictionary where the keys will be used for the keys parameter.
  • axis: Specifies the axis along which to concatenate the objects. The default value is 0.
    And so on, so in this format describe the other parameters as well.

## Example

mamtawardhani marked this conversation as resolved.
Show resolved Hide resolved
```py
import pandas
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import pandas
import pandas as pd

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you are using the abbreviation pd in the code


df1 = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
df2 = pd.DataFrame({'A': [5, 6], 'B': [7, 8]})

result = pd.concat([df1, df2])
print(result)

```

The example will result in a new DataFrame is returned by concatenating df1 and df2 along the rows:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The example will result in a new DataFrame is returned by concatenating df1 and df2 along the rows:
The example will result in a new `DataFrame` created by concatenating `df1` and `df2` along the rows. The output is as follows:


```shell
A B
0 1 2
1 3 4
0 5 6
1 7 8
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output that I'm getting is somewhat different, could you please run the code and check again? The is the output I'm getting:

   A  B
0  1  3
1  2  4
0  5  7
1  6  8

```
Loading