• 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)
    
    • 1

    Merge vertically by default
    在这里插入图片描述

    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)
    
    • 1
    • 2
    • 3

    a:
    在这里插入图片描述
    b:
    在这里插入图片描述
    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)
    
    • 1

    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'))
    
    • 1
    • 2
    • 3
    • 4
    • 5

    a:
    在这里插入图片描述
    b:
    在这里插入图片描述
    c:
    在这里插入图片描述

    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)
    
    • 1

    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')
    
    • 1
    • 2
    • 3
    • 4
    • 5

    a:
    在这里插入图片描述
    b:
    在这里插入图片描述
    c:
    在这里插入图片描述

  • 相关阅读:
    人工智能基础_机器学习039_sigmoid函数_逻辑回归_逻辑斯蒂回归_分类神器_代码实现逻辑回归图---人工智能工作笔记0079
    计算机存储器与存储结构
    Profiler内存泄露实际案例分析
    Decord库快速抽帧
    PMP 11.27 考试倒计时31天!来提分啦!
    【算法学习】-【双指针】-【盛水最多的容器】
    vscode 调试使用 make 编译的项目
    【无标题】
    openRPA开源项目源码编译
    什么是SSRF攻击?该如何防御SSRF攻击?
  • 原文地址:https://blog.csdn.net/sinat_28916141/article/details/127724621