pandas合并

concat

Concatenate pandas objects along a particular axis.

Allows 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.
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)

Merge vertically by default
pandas合并_第1张图片

a = pd.DataFrame(np.random.normal(0, 1, (3, 3)))
b = pd.DataFrame(np.random.normal(0, 1, (5, 5)))
c = pd.concat([a, b], axis=1, join='inner', ignore_index=True)

a:
pandas合并_第2张图片
b:
pandas合并_第3张图片
c:
在这里插入图片描述

merge

Merge DataFrame or named Series objects with a database-style join.

A named Series object is treated as a DataFrame with a single named
column.

The join is done on columns or indexes. If joining columns on columns,
the DataFrame indexes will be ignored. Otherwise if joining indexes on
indexes or indexes on a column or columns, the index will be passed
on. When performing a cross merge, no column specifications to merge
on are allowed.
pandas.merge

pandas.merge(left, right, how='inner', on=None, left_on=None, right_on=None, left_index=False, right_index=False, sort=False, suffixes=('_x', '_y'), copy=True, indicator=False, validate=None)

You can use Pandas merge to implement vlookup like functions

a = pd.DataFrame(np.random.normal(0, 1, (3, 3)))
a['merge'] = [1, 2, 3]
b = pd.DataFrame(np.random.normal(0, 1, (5, 5)), index=[2, 9, 10, 11, 12])
b['merge'] = [2, 3, 4, 5, 6]
c = pd.merge(a, b, how='left', on='merge', suffixes=('_a', '_b'))

a:
pandas合并_第4张图片
b:
pandas合并_第5张图片
c:
pandas合并_第6张图片

join

Join columns of another DataFrame.

Join columns with other DataFrame either on index or on a key column.
Efficiently join multiple DataFrame objects by index at once by
passing a list.
pandas.DataFrame.join

DataFrame.join(other, on=None, how='left', lsuffix='', rsuffix='', sort=False, validate=None)

joins index-on-index by default

a = pd.DataFrame(np.random.normal(0, 1, (3, 3)))
a['merge'] = [1, 2, 3]
b = pd.DataFrame(np.random.normal(0, 1, (5, 5)), index=[2, 9, 10, 11, 12])
b['merge'] = [2, 3, 4, 5, 6]
c = a.join(b,  rsuffix='_b')

a:
pandas合并_第7张图片
b:
pandas合并_第8张图片
c:
pandas合并_第9张图片

你可能感兴趣的:(pandas,pandas,python,数据分析)