Code: Select all
fruits = ['apple', 'orange', 'banana']
Code: Select all
numeric_fruits = [ (blank) fruit for fruit in fruits]
Ich habe versucht:
Code: Select all
import pandas as pd
fruits = ['apple', 'banana', 'orange']
numeric_fruits = [pd.get_dummies(fruit) for fruit in fruits]
print(numeric_fruits)
Code: Select all
[ apple
0 True, banana
0 True, orange
0 True]
Code: Select all
[[1, 0, 0],
[0, 1, 0],
[0, 0, 1]]
Mobile version