您的位置 首页 杂谈

pandas中concat用法

监控摄像头,office办公软件是什么,皇族老板天赐

import numpy as npimport pandas as pdarr=np.arange(12).reshape((3,4))In: arrOut:array(, , …

import numpy as npimport pandas as pdarr=np.arange(12).reshape((3,4))In: arrOut:array(, , ])In: np.concatenate()#numpy合并Out:array(, , , , , ])s1=pd.Series(,index=)s2=pd.Series(,index=)s3=pd.Series(,index=)In: pd.concat()#Series行合并Out:a 0b 1c 2d 3e 4f 5g 6dtype: int64In: pd.concat(,axis=1)#Series列合并Out: 0 1 2a 0.0 NaN NaNb 1.0 NaN NaNc NaN 2.0 NaNd NaN 3.0 NaNe NaN 4.0 NaNf NaN NaN 5.0g NaN NaN 6.0
s4=pd.Series(,index=)In: pd.concat(,axis=1,join=’inner’)#并集Out: 0 1a 0 0b 1 5In: pd.concat(,axis=1,join_axes=])#指定索引Out: 0 1a 0.0 0.0c NaN NaNb 1.0 5.0e NaN NaNIn: pd.concat(,keys=)#层次化索引Out:one a 0 b 1two c 2 d 3 e 4three f 5 g 6dtype: int64
In: pd.concat(,axis=1,keys=)#作为列Out: one two threea 0.0 NaN NaNb 1.0 NaN NaNc NaN 2.0 NaNd NaN 3.0 NaNe NaN 4.0 NaNf NaN NaN 5.0g NaN NaN 6.0
df1=pd.DataFrame(np.arange(6).reshape(3,2),index=,columns=)df2=pd.DataFrame(5 + np.arange(4).reshape(2,2),index=,columns=)In: pd.concat(,axis=1,keys=)#DataFrame列外索引Out: level1 level2 one two three foura 0 1 5.0 6.0b 2 3 NaN NaNc 4 5 7.0 8.0
In: pd.concat({‘level1′:df1,’level2’:df2},axis=1)#字典键做列外索引Out: level1 level2 one two three foura 0 1 5.0 6.0b 2 3 NaN NaNc 4 5 7.0 8.0
In: pd.concat(,axis=1,keys=,names=)#外内索引名字Out:upper level1 level2 lower one two three foura 0 1 5.0 6.0b 2 3 NaN NaNc 4 5 7.0 8.0
In: pd.concat(,keys=,names=)Out: four one three twoupper lower level1 a NaN 0.0 NaN 1.0 b NaN 2.0 NaN 3.0 c NaN 4.0 NaN 5.0level2 a 6.0 NaN 5.0 NaN c 8.0 NaN 7.0 NaN

———————作者:castingA3T来源:CSDN原文:https://blog.csdn.net/castinga3t/article/details/78998961版权声明:本文为博主原创文章,转载请附上博文链接!

本文来自网络,不代表加推新闻网立场,转载请注明出处:http://www.bafangmiaomu.com/shehui/97900/

作者: 头条新闻

为您推荐