-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[Term Entry] Python:Pandas built-in-functions: .concat() #4814
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
Merged
avdhoottt
merged 21 commits into
Codecademy:main
from
Liam-Dupeyron:Pandas_built-in-function_concat
Jul 25, 2024
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3e8eb6e
Create concat.md
Liam-Dupeyron aed673a
Lint + Format
Liam-Dupeyron d7f7475
Created concat.md file
Liam-Dupeyron a053608
Added information up to the Syntax
Liam-Dupeyron c2ec530
Finished concat.md
Liam-Dupeyron 1faeaf0
Update yarn.lock
mamtawardhani 5df8651
Update term-entry-template.md
mamtawardhani 5af3387
Edited line 19
Liam-Dupeyron 7873891
Applied changes and suggestions
Liam-Dupeyron 5f71e1d
Revised Syntax section
Liam-Dupeyron 533c568
Update concat.md
mamtawardhani d62e285
Added Codebyte Example
Liam-Dupeyron 162f765
Update concat.md
mamtawardhani 807d3dc
Merge branch 'main' into Pandas_built-in-function_concat
Liam-Dupeyron a27de53
Update content/pandas/concepts/built-in-functions/terms/concat/concat.md
avdhoottt c6ee38f
Update content/pandas/concepts/built-in-functions/terms/concat/concat.md
avdhoottt 0dfdbba
Catalog Content Changes
avdhoottt 6b7f982
Update content/pandas/concepts/built-in-functions/terms/concat/concat.md
avdhoottt ab4da8d
Update content/pandas/concepts/built-in-functions/terms/concat/concat.md
avdhoottt 35c6af8
Update content/pandas/concepts/built-in-functions/terms/concat/concat.md
avdhoottt de31ed9
Merge branch 'main' into Pandas_built-in-function_concat
avdhoottt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
content/pandas/concepts/built-in-functions/terms/concat/concat.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| --- | ||
| Title: '.concat()' | ||
| Description: 'Concatenates multiple dataframes or series along a particular axis.' | ||
| Subjects: | ||
| - 'Computer Science' | ||
| - 'Data Science' | ||
| Tags: | ||
| - 'Data Structures' | ||
| - 'Functions' | ||
| - 'Pandas' | ||
| CatalogContent: | ||
| - 'learn-python-3' | ||
| - 'paths/computer-science' | ||
| --- | ||
|
|
||
| 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. | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```pseudo | ||
| pandas.concat(objs, axis=0, join='outer', ignore_index=False, keys=None, levels=None, names=None, verify_integrity=False, sort=False, copy=True) | ||
| ``` | ||
|
|
||
| - `objs`: Denotes the objects to concatenate, which can be a sequence or mapping of pandas `Series` or `DataFrame` objects. It must be specified and can be passed as a list, tuple, dictionary, Series, or DataFrame. | ||
| - `axis`: Specifies the axis to concatenate the objects. The default value is 0 for rows, while 1 represents columns. | ||
| - `join`: Determines how to handle indexes on other axes. Options include "outer" (default), "inner," "left," or "right." | ||
| - `ignore_index`: If `True`, reset the index in the resulting DataFrame. The new axis will be labeled 0, ..., n-1. The default value is `False`. | ||
| - `keys`: Constructs a hierarchical index using the provided keys as the outermost level. The default value is `None`. | ||
| - `levels`: Specific levels to use for constructing a MultiIndex if keys are provided. The default value is `None`. | ||
| - `names`: Names for the levels generated in the hierarchical index. The default value is `None`. | ||
| - `verify_integrity`: If `True`, checks whether the new concatenated axis contains duplicates. The default value is `False`. | ||
| - `sort`: If `True`, sorts the resulting `Series` or `Dataframe` by the keys. The default value is `False`. | ||
| - `copy`: If `False`, avoid copying data unnecessarily. The default value is `True`. | ||
|
|
||
| > **Note:** Only the `objs` parameter is required; all other parameters are optional. | ||
|
|
||
| ## Example | ||
|
|
||
mamtawardhani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| The example below demonstrates the use of `.concat()` method: | ||
|
|
||
| ```py | ||
| import pandas as pd | ||
|
|
||
| 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` created by concatenating `df1` and `df2` along the rows. The output is as follows: | ||
|
|
||
| ```shell | ||
| A B | ||
| 0 1 3 | ||
| 1 2 4 | ||
| 0 5 7 | ||
| 1 6 8 | ||
| ``` | ||
|
|
||
| ## Codebyte Example | ||
|
|
||
| The code demonstrates the `.concat()` function on two DataFrames, concatenating `df1` and `df2` column-wise (`axis=1`) and using `keys` to create a hierarchical column index: | ||
|
|
||
| ```codebyte/python | ||
| import pandas as pd | ||
|
|
||
| df1 = pd.DataFrame({'A' : [1,2,3,4,5], 'B' : [6,7,8,9,10]}) | ||
| df2 = pd.DataFrame({'C' : [11,12,13,14,15], 'D' : [16,17,18,19,20]}) | ||
|
|
||
| result = pd.concat([df1, df2], axis=1, keys = ['df1', 'df2']) | ||
|
|
||
| print(result) | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you recheck if the
joinparameter supports "left" or "right" options?