Dummy variable
import pandas as pd
import numpy as np
s = ['a', 'b', np.nan]
df = pd.DataFrame(s)
df
0 | |
---|---|
0 | a |
1 | b |
2 | NaN |
df = pd.get_dummies(df[0], dummy_na=True)
df
a | b | NaN | |
---|---|---|---|
0 | 1 | 0 | 0 |
1 | 0 | 1 | 0 |
2 | 0 | 0 | 1 |
import pandas as pd
import numpy as np
s = ['a', 'b', np.nan]
df = pd.DataFrame(s)
df
0 | |
---|---|
0 | a |
1 | b |
2 | NaN |
df = pd.get_dummies(df[0], dummy_na=True)
df
a | b | NaN | |
---|---|---|---|
0 | 1 | 0 | 0 |
1 | 0 | 1 | 0 |
2 | 0 | 0 | 1 |