Python pandas: compare data and put together -
im using pandas read out csv-file , xlsx-file. both files have 1 common column numbers. save both datasets in 2 seperate lists. want check columns common values , add dataset second list first. criteria values must match. hope understand want do.
here lists: list 1:
fak-art fak-dat leist-dat kd-crm mw-bw eq-nr material \ 1 zpaf 2015-05-18 2015-05-31 tmd e 1003594714 g230ets 2 zpaf 2015-05-18 2015-05-31 tmd b 1000943473 g230ets 3 zpaf 2015-05-18 2015-05-31 tmd e 1000943608 g230ets 4 zpaf 2015-05-18 2015-05-31 tmd b 1000943704 g230ets 5 zpaf 2015-05-18 2015-05-31 tmd e 1000943823 g230ets 6 zpaf 2015-05-18 2015-05-31 tmd b 1000943985 g230ets 7 zpaf 2015-05-18 2015-05-31 tmd e 1000954774 g230ets 8 zpaf 2015-05-18 2015-05-31 tmd b 1000954790 g230ets 9 zpaf 2015-05-18 2015-05-31 tmd e 1000955082 g230ets 10 zpaf 2015-05-18 2015-05-31 tmd b 1000955097 g230ets 11 zpaf 2015-05-18 2015-05-31 tmd e 1001415563 g230ets 12 zpaf 2015-05-18 2015-05-31 tmd b 1001415566 g230ets 13 zpaf 2015-05-18 2015-05-31 tmd e 1001415569 g230ets 14 zpaf 2015-05-18 2015-05-31 tmd b 1003116180 g230ets 15 zpaf 2015-05-18 2015-05-31 tmd e 1003189748 g230ets 16 zpaf 2015-05-18 2015-05-31 tmd b 1003189752 g230ets 17 zpaf 2015-05-18 2015-05-31 tmd e 1003189753 g230ets
list 2
eq-nr ta 0 1003594714 sonstiges 1 1000943473 nan 2 1000943608 sonstiges 3 1000943704 sonstiges 4 1000943823 sonstiges 5 1000943985 sonstiges 6 1000954774 fmed 7 1000954790 fmed 8 1000955082 sdh 9 1000955097 nan 10 1001415563 sonstiges 11 1001415566 sonstiges 12 1001415569 sonstiges 13 1001496157 nan 14 1003116180 nan 15 1003189748 nan 16 1003189752 nan 17 1003189753 nan
now need hint how solve this. googled lot , didnt find solution problem. great if help.
use merge
:
print (pd.merge(df1, df2, on='eq-nr', how='left')) fak-art fak-dat leist-dat kd-crm mw-bw eq-nr material \ 0 zpaf 2015-05-18 2015-05-31 tmd e 1003594714 g230ets 1 zpaf 2015-05-18 2015-05-31 tmd b 1000943473 g230ets 2 zpaf 2015-05-18 2015-05-31 tmd e 1000943608 g230ets 3 zpaf 2015-05-18 2015-05-31 tmd b 1000943704 g230ets 4 zpaf 2015-05-18 2015-05-31 tmd e 1000943823 g230ets 5 zpaf 2015-05-18 2015-05-31 tmd b 1000943985 g230ets 6 zpaf 2015-05-18 2015-05-31 tmd e 1000954774 g230ets 7 zpaf 2015-05-18 2015-05-31 tmd b 1000954790 g230ets 8 zpaf 2015-05-18 2015-05-31 tmd e 1000955082 g230ets 9 zpaf 2015-05-18 2015-05-31 tmd b 1000955097 g230ets 10 zpaf 2015-05-18 2015-05-31 tmd e 1001415563 g230ets 11 zpaf 2015-05-18 2015-05-31 tmd b 1001415566 g230ets 12 zpaf 2015-05-18 2015-05-31 tmd e 1001415569 g230ets 13 zpaf 2015-05-18 2015-05-31 tmd b 1003116180 g230ets 14 zpaf 2015-05-18 2015-05-31 tmd e 1003189748 g230ets 15 zpaf 2015-05-18 2015-05-31 tmd b 1003189752 g230ets 16 zpaf 2015-05-18 2015-05-31 tmd e 1003189753 g230ets ta 0 sonstiges 1 nan 2 sonstiges 3 sonstiges 4 sonstiges 5 sonstiges 6 fmed 7 fmed 8 sdh 9 nan 10 sonstiges 11 sonstiges 12 sonstiges 13 nan 14 nan 15 nan 16 nan
Comments
Post a Comment