<>DataFrame

1. establish DataFrame
# Create an empty DataFrame #df = pd.DataFrame(columns=[' license plate number ', ' Model ', ' label ']) df = pd.
DataFrame([[' Shanghai C 100232', ' Benz ', 'Y'], [' Lu A 801353', ' audi ', 'N'], [' Yu H 666132',
' bmw ', 'Y']]) df.columns = [' license plate number ', ' Model ', ' label '] license plate number Model label 0 Shanghai C 100232 Benz Y 1 Lu A
801353 audi N 2 Yu H 666132 bmw Y
2. mapping Transformation 【 Model 】 Column data
# Benz -> 1, audi -> 2, bmw -> 3. mapping_1 = {' Benz ': 1, ' audi ': 2, ' bmw ': 3} df[' Model '] =
df[' Model '].map(mapping_1) license plate number Model label 0 Shanghai C 100232 1 Y 1 Lu A 801353 2 N 2 Yu H 666132 3
Y
3. handle 【 license plate number 】 Column data
# Shanghai C 100232 -> Shanghai C , Lu A 801353 -> Lu A , Yu H 666132 -> Yu H. df[' license plate number '] = list(map(lambda
var: var[:2],df[' license plate number '].tolist())) license plate number Model label 0 Shanghai C 1 Y 1 Lu A 2 N 2 Yu H 3 Y
4. handle 【 label 】 Column data
# Y ->0 , N ->1 , Y ->0. mapping_2 = {value:ind for ind,value in enumerate(set(
df[' label ']))} df[' label '] = df[' label '].map(mapping_2) license plate number Model label 0 Shanghai C 1 0 1 Lu A 2 1 2 Yu H
3 0
5. one_hot handle 【 license plate number 】
pd.get_dummies(df) #pd.get_dummies(df[' license plate number ']) Model label license plate number _ Shanghai C license plate number _ Yu H license plate number _ Lu A 0 1 0
1 0 0 1 2 1 0 0 1 2 3 0 0 1 0

Technology
©2019-2020 Toolsou All rights reserved,
Hackbar Using the tutorial python primitive -- lock Lock experiment 11-1-6 Output string at specified position (20 branch )( Essence )2020 year 6 month 26 day C# Class library model PageInputPowerShell Use in WebClient Download the file and get the download progress Determine whether the current object is an array 4 Methods ( Essence )2020 year 6 month 26 day C# Class library Exception handling help class Novices play hiss HI3520D Development board ( One , upgrade )LED Scrolling text use PyMC3 Bayesian statistical analysis was performed ( code + example )