Python3数据科学汇总: https://blog.csdn.net/weixin_41793113/article/details/99707225
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
arr1 = np.arange(9).reshape(3,3)
arr1 #生成0-8的矩阵
arr2 = np.arange(9).reshape(3,3)
arr2
np.concatenate([arr1,arr2],axis=1) #默认 axis=0
np.concatenate([arr1,arr2])
s1 = Series([1,2,3], index=['X','Y','Z'])
s1
s2 = Series([4,5], index=['A','B'])
s2
pd.concat([s1,s2])
df1 = DataFrame(np.random.randn(4,3), columns=['X','Y','Z'])
df1
df2 = DataFrame(np.random.randn(3,3), columns=['X','Y','A'])
df2
pd.concat([df1,df2])
s1 = Series([2, np.nan, 4, np.nan], index=['A','B','C','D'])
s1
s2 = Series([10,20,30,40], index=['D','B','C','A'])
s2
s1.combine_first(s2) #可以看出s1中空的值NaN用s2队友的索引填充
df1 = DataFrame({
'X': [1, np.nan, 3, np.nan],
'Y': [5, np.nan, 7, np.nan],
'Z': [9, np.nan, 11,np.nan]
})
df1
df2 = DataFrame({
'Z':[np.nan, 10, np.nan, 12],
'A':[1,2,3,4]
})
df2
df1.combine_first(df2) ##可以看出和一维是相似的 df1没有的属性会加上去,有的属性则如果有NaN就用df2填充