-1

enter image description here I want to add a column for duration which subtracts max date from min date for each company(ComapnyName)

  • 1
    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 Aug 28 '18 at 08:00

1 Answers1

0

Use:

m1 = df.groupby('CompanyName')['Date'].transform('max')
m2 = df.groupby('CompanyName')['Date'].transform('min')
df['duration'] = (m1 - m2).dt.days
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252