import pandas as pd
df = pd.DataFrame([
['green', 'M', 10.1],
['red', 'L', 13.5],
['blue', 'XL', 15.3]])
df.columns = ['color', 'size', 'prize']
df
df
[out:]
color | size | prize | ||
---|---|---|---|---|
0 | green | M | 10.1 | |
1 | red | L | 13.5 | |
2 | blue | XL | 15.3 |
pd.get_dummies(df)
prize | color_blue | color_green | color_red | size_L | size_M | size_XL | |
---|---|---|---|---|---|---|---|
0 | 10.1 | 0 | 1 | 0 | 0 | 1 | 0 |
1 | 13.5 | 0 | 0 | 1 | 1 | 0 | 0 |
2 | 15.3 | 1 | 0 | 0 | 0 | 0 | 1 |