0

I have two dateframes, dfItem and dfCustomers, that I want to merge. dfItem consists of invoices over a ten year period, while dfCustomers consist of the customer number and customer name.

I want to create a new df where the corresponding kundenavn (customer name) is added to each row on dfItem. The common column is kundenummer (customer number).

Any suggestions are appreciated.

  • 3
    Welcome to StackOverflow. Please take the time to read this post on [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) may also be useful. – jezrael May 30 '17 at 08:36
  • 1
    This will help https://pandas.pydata.org/pandas-docs/stable/merging.html. – Vishnu Upadhyay May 30 '17 at 08:38

2 Answers2

0

I guess it would be better if you provided more info but i guess this will do according to the information you provided

df=pd.merge( dfItem ,dfCustomers,on=[' kundenummer'])
Eliethesaiyan
  • 2,327
  • 1
  • 22
  • 35
0

is this what you wanted?

result = dfItem.merge(dfCustomers, how='left', on=['kundenummer'])
zipa
  • 27,316
  • 6
  • 40
  • 58
  • This produces the desired layout but all the values in the series 'kundenavn' (customer name) are NaN. Should I revise my question or is the info supplied adequate? – Preben Hesvik May 30 '17 at 09:02
  • Data that you provided doesn't have any match in `'kundenummer'`. `JOIN` or `merge` in `pandas` works by matching same column values and returns `NaN` if value is not found. – zipa May 30 '17 at 09:25
  • Thank you. You pointed me in the right direction. Both of my data frames included a a string in the column 'kundenummer' that I didn't know about. Your solution worked after removing the strings. How do I mark your answer as correct? PS: I have been trying to figure this out for several days now and I finally got around to ask for help. THANK YOU :) – Preben Hesvik May 30 '17 at 10:38
  • 1
    [Accepting Answers: How does it work?](https://meta.stackexchange.com/a/5235/345643) should be helpful. And you are welcome :) – zipa May 30 '17 at 10:40