Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

separating numeric and categorical feature using loop

# create a list of all categorical variables
# initiate an empty list to store the categorical variables
categorical=[]

# use for loop to check the data type of each variable
for column in df_vaccine:
    
    # use 'if' statement with condition to check the categorical type 
    if is_string_dtype(df_vaccine[column]):
        
        # append the variables with 'categoric' data type in the list 'categorical'
        categorical.append(column)
# dataframe with categorical features
# 'categorical' contains a list of categorical variables
df_cat = df_vaccine[categorical]

# dataframe with numerical features
# use 'drop()' to drop the categorical variables
# 'axis = 1' drops the corresponding column(s)
df_num = df_vaccine.drop(categorical, axis = 1)      
Comment

PREVIOUS NEXT
Code Example
Python :: program to add two numbers in python 
Python :: FizzBuzz in Python Using Conditional Statements 
Python :: Data type based on rows 
Python :: nbt python 
Python :: saving a dta file 
Python :: python is not defined 
Python :: how parse date python no specific format 
Python :: Code example of Python Modulo Operator with Exception handling 
Python :: Code Example of Comparing None with None type 
Python :: Using Python Permutations function on a String with extra parameter 
Python :: Code to find maximum number using if else 
Python :: cubic interpolation python 
Python :: view(-1 1) pytorch 
Python :: python combine images horizontally next to each other 
Python :: selenium emojis 
Python :: *9c0xxbz] 
Python :: Elasticsearch scroll with Parallelism r 
Python :: jupyterlab collapsing cells 
Python :: intervalle de temps python 
Python :: use fetchone() function to find duplicate row. 
Python :: Python NumPy require Function Syntax 
Python :: gdal split bog image to small python 
Python :: torch mean of tensor 
Python :: python model feature importance 
Python :: Program to illustrate the use of nested if statement Average in python Grade =80 and above A =70 and <80 B =60 and <70 C =50 and <60 D Otherwise 
Python :: django view - apiview decorator (urls.py config) 
Python :: fibo_itrativ 
Python :: Concatenation of two range() functions 
Python :: Use one function for the "ComboboxSelected", to read multiple combobox 
Python :: loop regex 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =