concatenate
英 /kən’kætɪneɪt/ 美 /kɑn’kætə,net/
adj. 连接的,连结的,连锁的
v. 连接,连结,使连锁
concat
concat(objs, axis=0, join=‘outer’, join_axes=None, ignore_index=False, keys=None, levels=None, names=None, verify_integrity=False, sort=None, copy=True)
| 参数 | 含义 |
|---|---|
| objs | a sequence or mapping of Series, DataFrame, or Panel objects(论学好英语的重要性)是一个序列,其元素是向量或者矩阵 |
| axis | 这个就是很迷,{0/‘index’, 1/‘columns’},The axis to concatenate along |
| join | {‘inner’, ‘outer’}How to handle indexes on other axis(es) |
| join_axes | 决定concat方向上保留哪些标签,与axis配合使用 |
| ignore_index | If True, do not use the index values along the concatenation axis. The resulting axis will be labeled 0, …, n - 1. |
| objs | |
| objs |
axis
确定拼接方向
import pandas as pd
import numpy as np
d1 = pd.DataFrame(np.random.rand(4, 3), ['a', 'b', 'c', 'd'], [1, 2, 3])
d2 = pd.DataFrame(np.arange(1, 13).reshape(4, 3), ['a', 'b', 'c', 'd'], [1, 2, 3])
print(pd.concat([d1, d2], axis=1)) # 列
print(pd.concat([d1, d2], axis=0)) # 行

ignore_index
是否保留原有的index方向的标签
import pandas as pd
import numpy as np
d1 = pd.DataFrame(np.random.rand(4, 3), ['a', 'b', 'c', 'd'], [1, 2, 3])
d2 = pd.DataFrame(np.arange(1, 13).reshape(4, 3), ['a', 'b', 'c', 'd'], [1, 2, 3])
print(pd.concat([d1, d2], ignore_index=True))

join
关于数据库里的内连接、左连接、右连接、全连接
- inner大概对应内连接,只得到橡胶的数据
- outter大概对应全连接,全得到,没有的用NaN表示
import pandas as pd
import numpy as np
d1 = pd.DataFrame(np.random.rand(4, 3), ['a', 'b', 'c', 'd'], [1, 2, 3])
d2 = pd.DataFrame(np.arange(1, 13).reshape(4, 3), ['b', 'c', 'd', 'e'], [3, 4, 5])
print(pd.concat([d1, d2]))
print(pd.concat([d1, d2], join='inner'))

join_axes
表示concat的轴上保留哪些label,与axis配个使用
import pandas as pd
import numpy as np
d1 = pd.DataFrame(np.random.rand(4, 3), ['a', 'b', 'c', 'd'], [1, 2, 3])
d2 = pd.DataFrame(np.arange(1, 13).reshape(4, 3), ['b', 'c', 'd', 'e'], [3, 4, 5])
print(pd.concat([d1, d2], axis=1, join_axes=[d1.index]))
print(pd.concat([d1, d2], join_axes=[d1.columns]))

最后
以上就是可耐白羊最近收集整理的关于pandas——concat(concatenate)concat的全部内容,更多相关pandas——concat(concatenate)concat内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复