0

I have a df that looks like:

import pandas as pd

df = pd.DataFrame({'car_id':[01,02,03,04,05],
               'crash_severinity' :[unknown, possible injury,not injury,possible injury, unknown]})

df

I would like it to look like this

df

df = pd.DataFrame({'car_id':[01,02,03,04,05],
               'unknown' :[1,0,0,0,1],
               'possible injury' :[0,1,0,1,0]
               'not injury:[0,0,1,0,0]})

thanking you in advance!!

Dear_Gabe
  • 31
  • 2

1 Answers1

0

This is what you are looking for:

df = pd.get_dummies(df)

Output is:

    crash_severity_not injured  crash_severity_possible injury  crash_severity_unknown
0                0                            0                           1
1                0                            1                           0
2                1                            0                           0
3                0                            1                           0
4                0                            0                           1
Julien Roullé
  • 622
  • 4
  • 14