pandas中merge,append,concat的用法

merge

In [1]: import pandas as pd

In [2]: import numpy as np

In [3]: from pandas import DataFrame
In [6]: df1 = pd.DataFrame({'fund_id':[1,2,3],'statistic_date':[11,22,33],'benc
   ...: hmark':[111,222,333],'a':[1111,2222,3333]})

In [7]: df2 = pd.DataFrame({'fund_id':[1,2,3],'statistic_date':[11,22,33],'benc
   ...: hmark':[111,222,333],'b':[1111,2222,3333]})

In [8]: df1
Out[8]:
      a  benchmark  fund_id  statistic_date
0  1111        111        1              11
1  2222        222        2              22
2  3333        333        3              33

In [9]: df2
Out[9]:
      b  benchmark  fund_id  statistic_date
0  1111        111        1              11
1  2222        222        2              22
2  3333        333        3              33

In [11]: df = pd.merge(df1, df2, how='outer', left_on=['fund_id','statistic_dat
    ...: e','benchmark'], right_on=['fund_id','statistic_date','benchmark'])

In [12]: df
Out[12]:
      a  benchmark  fund_id  statistic_date     b
0  1111        111        1              11  1111
1  2222        222        2              22  2222
2  3333        333        3              33  3333

In [13]:

你可能感兴趣的:(python及后端,数据分析)