The young planetary system surrounding the star β Pictoris harbours active minor bodies1, 2, 3, 4, 5, 6. These asteroids and comets produce a large amount of dust and gas through collisions and evaporation, as happened early in the history of our Solar System7. Spectroscopic observations of β Pictoris reveal a high rate of transits of small evaporating bodies8, 9, 10, 11, that is, exocomets. Here we report an analysis of more than 1,000 archival spectra gathered between 2003 and 2011, which provides a sample of about 6,000 variable absorption signatures arising from exocomets transiting the disk of the parent star. Statistical analysis of the observed properties of these exocomets allows us to identify two populations with different physical properties. One family consists of exocomets producing shallow absorption lines, which can be attributed to old exhausted (that is, strongly depleted in volatiles) comets trapped in a mean motion resonance with a massive planet. Another family consists of exocomets producing deep absorption lines, which may be related to the recent fragmentation of one or a few parent bodies. Our results show that the evaporating bodies observed for decades in the β Pictoris system are analogous to the comets in our own Solar System.