This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
index = ['Ana', 'Ian', 'Eva', 'Dan', 'Kim'] | |
columns = ['Color', 'Type', 'Length'] | |
ana = ['Brown', 'Straight', 'Short'] | |
ian = ['Black', 'Wavy', 'Short'] | |
eva = ['Red', 'Curly', 'Long'] | |
dan = ['Blonde', 'Straight', 'Long'] | |
kim = ['Brown', 'Curly', 'Medium'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
length_mapping ={'Short' : 1, | |
'Medium': 2, | |
'Long' : 3} | |
df['Length'] = df['Length'].map(length_mapping) | |
df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df = pd.get_dummies(df) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df = pd.get_dummies(df, drop_first=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reverse_length_mapping ={1 : 'Short', | |
2 : 'Medium', | |
3 : 'Long' } | |
df['Length'] = df['Length'].map(reverse_length_mapping) | |
df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reverse_length_mapping = {v: k for k, vi in length_mapping.items()} | |
df['Length'] = df['Length'].map(reverse_length_mapping) | |
df |