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]:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值