import pandas as pd import numpy as np # Pandas 可以根据索引实现数据自动对齐,索引不重合的部分被置为NaN df1 = pd.DataFrame(np.random.randint(low=1, high=10, size=(3,4)), columns=['a','b','c','d']) df2 = pd.DataFrame(np.random.randint(low=1, high=10, size=(4,5)), columns=['a','b','c','d','e']) df3 = pd.DataFrame(np.random.randint(low=1, high=10, size=(3,4)), columns=['e','f','g','h']) print(df1) print(df2) print(df3) print(df1 + df2) print(df1 + df3)