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

  • 相关阅读:
    ssm毕设项目学生公寓智慧管理系统d6472(java+VUE+Mybatis+Maven+Mysql+sprnig)
    es 使用wildcard通配符检索不到的问题
    【JAVAEE基础学习(16)】--简述ElasticSearch
    Word不计算封面、目录页数将正文页码修改为第几页共几页的格式
    章节三:RASA Domain介绍
    python-json校验-jsonpath
    Windows 修vscode的插件安装和缓存目录 释放C盘空间
    双周赛114(模拟、枚举 + 哈希、DFS)
    MyBatis-Flex学习手册
    无代码开发段落入门教程
  • 原文地址:https://blog.csdn.net/sinat_28916141/article/details/127724621