-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
3e8eb6e
aed673a
d7f7475
a053608
c2ec530
1faeaf0
5df8651
5af3387
7873891
5f71e1d
533c568
d62e285
162f765
807d3dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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' | ||||||
--- | ||||||
|
||||||
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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The syntax should include all the parameters from the documentation of the
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 | | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the parameters need to be described in the below format:
|
||||||
## Example | ||||||
|
||||||
mamtawardhani marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
```py | ||||||
import pandas | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```shell | ||||||
A B | ||||||
0 1 2 | ||||||
1 3 4 | ||||||
0 5 6 | ||||||
1 7 8 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
|
||||||
``` |
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.
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.
added relevant subjects and tags from the documents