Pandas: Data Manipulation - concat() function
concat() function
The concat() function is used to concatenate pandas objects along a particular axis with optional set logic along the other axes.
Syntax:
pandas.concat(objs, axis=0, join='outer', join_axes=None, ignore_index=False, keys=None, levels=None, names=None, verify_integrity=False, sort=None, copy=True)
Parameters:
Name | Description | Type | Default | Required / Optional |
---|---|---|---|---|
objs | A sequence or mapping of Series or DataFrame objects. If a dict is passed, the sorted keys will be used as the keys argument, unless it is passed, in which case the values will be selected (see below). |
Series or DataFrame objects | Required | |
axis | The axis to concatenate along. | {0/’index’, 1/’columns’} | Default: 0 | Optional |
join | Handle indexes on other axis (or axes). | {‘inner’, ‘outer’}
|
Default: ‘outer’ | Optional |
left_on | Field name to join on in left DataFrame. | label | Optional | |
ignore_index | Useful to concate objects where the concatenation axis does not have meaningful indexing information. | bool | Default: False | Optional |
keys | Construct hierarchical index using the passed keys as the outermost level. | sequence | Default: None | Optional |
levels | Specific levels (unique values) to use for constructing a MultiIndex. Otherwise they will be inferred from the keys. | list of sequences | Default: None | Optional |
names | Names for the levels in the resulting hierarchical index. | list | Default: None | Optional |
verify_integrity | Field names to match on in the left DataFrame. | bool | Default: False | Optional |
sort | Sort non-concatenation axis if it is not already aligned when join is "outer". | bool | Default: None | Optional |
copy | Suffix to apply to overlapping column names in the left and right side, respectively. | bool | Default: True |
Optional |
Returns:
object
Ttype of objects:
- When concatenating all Series along the index (axis=0), a Series is returned.
- When objs contains at least one DataFrame, a DataFrame is returned.
- When concatenating along the columns (axis=1), a DataFrame is returned.
Example:
Download the Pandas DataFrame Notebooks from here.
Previous: merge_asof() function
Next: get_dummies() function
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/pandas/concat.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics