Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

convert categorical variable to numeric python

# get all categorical columns in the dataframe
catCols = [col for col in df1.columns if df1[col].dtype=="O"]

from sklearn.preprocessing import LabelEncoder

lb_make = LabelEncoder()

for item in catCols:
    df1[item] = lb_make.fit_transform(df1[item])
Comment

transform categorical variables python

from sklearn.preprocessing import LabelEncoder

lb_make = LabelEncoder()
obj_df["make_code"] = lb_make.fit_transform(obj_df["make"])
obj_df[["make", "make_code"]].head(11)
Comment

how to convert categorical data to numerical data in python

pd.get_dummies(obj_df, columns=["body_style", "drive_wheels"], prefix=["body", "drive"]).head()
Comment

how to convert categorical data to numerical data in python

obj_df["body_style"] = obj_df["body_style"].astype('category')
obj_df.dtypes
Comment

Converting categorical variable to numeric variable in python

## Converting Age to numeric variable

df['Gender']=pd.get_dummies(df['Gender'],drop_first=1)
df.head()
Comment

PREVIOUS NEXT
Code Example
Python :: python fill table wiget 
Python :: write csv python pandas stack overflow 
Python :: import matplotlib python 
Python :: aioschedule python 
Python :: join pyspark stackoverflow 
Python :: pandas create dataframe of ones 
Python :: how to get total number of rows in listbox tkinter 
Python :: get wav file in dir 
Python :: how to install python3.6 on ubuntu 
Python :: print no new line python 
Python :: factors addition in pyhone 
Python :: save video cv2 
Python :: poetry take the dependencies from requirement.txt 
Python :: rearrange list 
Python :: streamlit button to load a file 
Python :: how to change colour of rows in csv using pandas 
Python :: confusion matrix from two columns pandas dataframe 
Python :: absolute value of int python 
Python :: add element to heap python 
Python :: python saveAsTextFile 
Python :: python scratch cloud variabelen 
Python :: how to save the history of keras model 
Python :: python imread multiple images 
Python :: how to make a pygame window 
Python :: how to find exact distance 
Python :: where to find python3 interpreter 
Python :: python write list to text file 
Python :: extract n grams from text python 
Python :: convert letters to numbers in python 
Python :: python transpose list 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =