|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
# 在pandas里提供concat函数可以将形参给出的列表里的各个pandas的数据拼接成一个大的数据。
# Pandas在做数据拼接的时候提供类似于数据库的内连接、外连接的操作。
# 默认是outer join即外连接,可以使用参数指定连接的类型为内连接inner join。
# inner join类型的拼接实际是求两个集的交集。
- import numpy as np
- import pandas as pd
- col1 = "hello the cruel world".split()
- col2 = "hello the nice world".split()
- idx1 = ["a", "b", "c", "d"]
- idx2 = ["a", "b", "d", "e"]
- val1 = np.arange(16).reshape(4,4)
- val2 = np.arange(20,36).reshape(4,4)
- df1 = pd.DataFrame(val1,index=idx1,columns=col1)
- df2 = pd.DataFrame(val2,index=idx2,columns=col2)
- df12 = pd.concat([df1, df2],join='outer')
- df12_in = pd.concat([df1, df2],join='inner')
- print ('默认concat拼接******\n',df12)
- print ('inner——concat拼接**\n',df12_in)
复制代码 |
|