pandas.concat¶
pandas.concat[objs, axis=0, join='outer', ignore_index=False, keys=None, levels=None, names=None, verify_integrity=False, sort=False, copy=True][source]¶Concatenate pandas objects along a particular axis with optional set logic along the other axes.
Can also add a layer of hierarchical indexing on the concatenation axis, which may be useful if the labels are the same [or overlapping] on the passed axis number.
Parametersobjsa sequence or mapping of Series or DataFrame objectsIf a mapping 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]. Any None objects will be dropped silently unless they are all None in which case a ValueError will be raised.
axis{0/index, 1/columns}, default 0The axis to concatenate along.
join{inner, outer}, default outerHow to handle indexes on other axis [or axes].
ignore_indexbool, default FalseIf True, do not use the index values along the concatenation axis. The resulting axis will be labeled 0, , n - 1. This is useful if you are concatenating objects where the concatenation axis does not have meaningful indexing information. Note the index values on the other axes are still respected in the join.
keyssequence, default NoneIf multiple levels passed, should contain tuples. Construct hierarchical index using the passed keys as the outermost level.
levelslist of sequences, default NoneSpecific levels [unique values] to use for constructing a MultiIndex. Otherwise they will be inferred from the keys.
Names for the levels in the resulting hierarchical index.
verify_integritybool, default FalseCheck whether the new concatenated axis contains duplicates. This can be very expensive relative to the actual data concatenation.
sortbool, default FalseSort non-concatenation axis if it is not already aligned when join is outer. This has no effect when join='inner', which already preserves the order of the non-concatenation axis.
Changed in version 1.0.0: Changed to not sort by default.
If False, do not copy data unnecessarily.
Returnsobject, type of objsWhen 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.
See also
Series.appendConcatenate Series.
Concatenate DataFrames.
DataFrame.joinJoin DataFrames using indexes.
DataFrame.mergeMerge DataFrames by indexes or columns.
Notes
The keys, levels, and names arguments are all optional.
A walkthrough of how this method fits in with other tools for combining pandas objects can be found here.
Examples
Combine two Series.
Clear the existing index and reset it in the result by setting the ignore_index option to True.
Add a hierarchical index at the outermost level of the data with the keys option.
Label the index keys you create with the names option.
Combine two DataFrame objects with identical columns.
Combine DataFrame objects with overlapping columns and return everything. Columns outside the intersection will be filled with NaN values.
Combine DataFrame objects with overlapping columns and return only those that are shared by passing inner to the join keyword argument.
Combine DataFrame objects horizontally along the x axis by passing in axis=1.
Prevent the result from including duplicate index values with the verify_integrity option.