Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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 contionous data into categorical data in python

pd.cut(df.Age,bins=[0,2,17,65,99],labels=['Toddler/Baby','Child','Adult','Elderly'])
# where bins is cut off points of bins for the continuous data 
# and key things here is that no. of labels is always less than 1
Comment

how to change value of categorical variable in python

df['Gender'].str[0].str.upper().map({'M':'Male', 'F':'Female'})
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 :: PY | websocket - client 
Python :: python check if number in string 
Python :: know the type of variable in python 
Python :: text from xml doc in python 
Python :: sklearn train test split 
Python :: python set match two list 
Python :: pandas count number of repetitions of each diferent value 
Python :: sort a dict by values 
Python :: python how to check in a list 
Python :: how to python 
Python :: python dataframe save 
Python :: while input is not empty python 
Python :: waiting in python. time , sleep 
Python :: properties of tuples in python 
Python :: If elif else 
Python :: self in python 
Python :: python get last item in a list 
Python :: models in django 
Python :: python redirect with button click 
Python :: print list in one line python 
Python :: create column with values mapped from another column python 
Python :: how to stop thread python 
Python :: pandas replace values 
Python :: python convert list of lists of strings to int 
Python :: read csv python 
Python :: how to remove role discord bot python 
Python :: how to check if a variable holds a class reference in python 
Python :: how to comment text in python 
Python :: merge 2 dataframes in python 
Python :: binary to decimal in python without inbuilt function 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =