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
Prev Previous commit
Next Next commit
Finished concat.md
  • Loading branch information
Liam-Dupeyron committed Jun 21, 2024
commit c2ec5305de7d763bb4afd835461ccd048268c23c
41 changes: 31 additions & 10 deletions content/pandas/concepts/built-in-functions/terms/concat/concat.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,39 @@ pandas.concat(objs)

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 |

## Example

mamtawardhani marked this conversation as resolved.
Show resolved Hide resolved
[Text, code, images, etc. about example 1]
```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]})

## Codebyte Example (if applicable)
result = pd.concat([df1, df2])
print(result)

We can currently support:
```

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:


- Python
- JavaScript
- Ruby
- C++
- C#
- Go
- PHP
```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

```