Equivalent of R’s factor function in Pandas

import pandas as pd

accidents = pd.DataFrame({
  'Accident_Severity': [1, 2, 3, 1]
  })
di = {
  1: 'fatal',
  2: 'serious',
  3: 'slight'
}
accidents2 = accidents.replace({"Accident_Severity": di})

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top