Daten mit pandas verknüpfen
Aaren Stubberfield
Instructor
.merge()
-Methode:
on
, left_on
und right_on
how
(links, rechts, innen, außen)suffixes
df1.merge(df2)
merge_ordered()
-Methode:
on
, left_on
und right_on
how
(links, rechts, innen, außen)suffixes
pd.merge_ordered(df1, df2)
Tabellenname: aapl
date close
0 2007-02-01 12.087143
1 2007-03-01 13.272857
2 2007-04-01 14.257143
3 2007-05-01 17.312857
4 2007-06-01 17.434286
Tabellenname: mcd
date close
0 2007-01-01 44.349998
1 2007-02-01 43.689999
2 2007-03-01 45.049999
3 2007-04-01 48.279999
4 2007-05-01 50.549999
import pandas as pd
pd.merge_ordered(aapl, mcd, on='date', suffixes=('_aapl','_mcd'))
date close_aapl close_mcd
0 2007-01-01 NaN 44.349998
1 2007-02-01 12.087143 43.689999
2 2007-03-01 13.272857 45.049999
3 2007-04-01 14.257143 48.279999
4 2007-05-01 17.312857 50.549999
5 2007-06-01 17.434286 NaN
pd.merge_ordered(aapl, mcd, on='date',
suffixes=('_aapl','_mcd'),
fill_method='ffill')
date close_aapl close_mcd
0 2007-01-01 NaN 44.349998
1 2007-02-01 12.087143 43.689999
2 2007-03-01 13.272857 45.049999
3 2007-04-01 14.257143 48.279999
4 2007-05-01 17.312857 50.549999
5 2007-06-01 17.434286 50.549999
pd.merge_ordered(aapl, mcd, on='date',
suffixes=('_aapl','_mcd'))
date close_aapl close_mcd
0 2007-01-01 NaN 44.349998
1 2007-02-01 12.087143 43.689999
2 2007-03-01 13.272857 45.049999
3 2007-04-01 14.257143 48.279999
4 2007-05-01 17.312857 50.549999
5 2007-06-01 17.434286 NaN
Daten mit pandas verknüpfen