Тёмный

Convert Categorical Columns to Numerical Columns 

AI ML & GRC 12.0
Подписаться 880
Просмотров 19 тыс.
50% 1

Опубликовано:

 

28 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 14   
@SarielDatalab
@SarielDatalab 8 месяцев назад
Awesome ! This saves a lot of time converting them one at time. Thank you so much!!
@dr_munchkin
@dr_munchkin 6 месяцев назад
My categorical variables are not getting converted into uint8 they are still bool - everything is correct! But why am in unable to convert
@sivakumar-rz9nc
@sivakumar-rz9nc 6 месяцев назад
df_cat = df.select_dtypes(include=['object']) # Select categorical columns df_num = df.select_dtypes(include=['number']) # Select numeric columns # Convert categorical variables to numerical using one-hot encoding df_cat_encoded = pd.get_dummies(df_cat, drop_first=True) # Apply one-hot encoding # Identify boolean columns and convert them to numeric boolean_cols = df_cat_encoded.columns[df_cat_encoded.dtypes == 'bool'] df_cat_encoded[boolean_cols] = df_cat_encoded[boolean_cols].astype(int) # Concatenate the numerical and encoded categorical columns df_ml = pd.concat([df_num, df_cat_encoded], axis=1) # Concatenate along columns (axis=1) # Display the first few rows of the combined DataFrame df_ml.head(2)
@preciousosokoya6346
@preciousosokoya6346 Год назад
Awesome Video
@sivakumar-rz9nc
@sivakumar-rz9nc 6 месяцев назад
Hello all, ###the above code requires some changes, this is the modified code df_cat = df.select_dtypes(include=['object']) # Select categorical columns df_num = df.select_dtypes(include=['number']) # Select numeric columns # Convert categorical variables to numerical using one-hot encoding df_cat_encoded = pd.get_dummies(df_cat, drop_first=True) # Apply one-hot encoding # Identify boolean columns and convert them to numeric boolean_cols = df_cat_encoded.columns[df_cat_encoded.dtypes == 'bool'] df_cat_encoded[boolean_cols] = df_cat_encoded[boolean_cols].astype(int) # Concatenate the numerical and encoded categorical columns df_ml = pd.concat([df_num, df_cat_encoded], axis=1) # Concatenate along columns (axis=1) # Display the first few rows of the combined DataFrame df_ml.head(2)
@--NallapuNaveen
@--NallapuNaveen 2 месяца назад
thanku brother👍
@JyotirmoyeeRoy
@JyotirmoyeeRoy 6 месяцев назад
It's showing a error "df is not defined ". What to do
@sivakumar-rz9nc
@sivakumar-rz9nc 6 месяцев назад
df_cat = df.select_dtypes(include=['object']) # Select categorical columns df_num = df.select_dtypes(include=['number']) # Select numeric columns # Convert categorical variables to numerical using one-hot encoding df_cat_encoded = pd.get_dummies(df_cat, drop_first=True) # Apply one-hot encoding # Identify boolean columns and convert them to numeric boolean_cols = df_cat_encoded.columns[df_cat_encoded.dtypes == 'bool'] df_cat_encoded[boolean_cols] = df_cat_encoded[boolean_cols].astype(int) # Concatenate the numerical and encoded categorical columns df_ml = pd.concat([df_num, df_cat_encoded], axis=1) # Concatenate along columns (axis=1) # Display the first few rows of the combined DataFrame df_ml.head(2)
@sangitaahire8569
@sangitaahire8569 Год назад
Columns must be same length as key so what I do
@Rahul-op2vc
@Rahul-op2vc 11 месяцев назад
hey did you get the answer to this.. I am getting the same error
@sivakumar-rz9nc
@sivakumar-rz9nc 6 месяцев назад
df_cat = df.select_dtypes(include=['object']) # Select categorical columns df_num = df.select_dtypes(include=['number']) # Select numeric columns # Convert categorical variables to numerical using one-hot encoding df_cat_encoded = pd.get_dummies(df_cat, drop_first=True) # Apply one-hot encoding # Identify boolean columns and convert them to numeric boolean_cols = df_cat_encoded.columns[df_cat_encoded.dtypes == 'bool'] df_cat_encoded[boolean_cols] = df_cat_encoded[boolean_cols].astype(int) # Concatenate the numerical and encoded categorical columns df_ml = pd.concat([df_num, df_cat_encoded], axis=1) # Concatenate along columns (axis=1) # Display the first few rows of the combined DataFrame df_ml.head(2)
@Ali-ig4tg
@Ali-ig4tg 5 месяцев назад
@@sivakumar-rz9nc sir i did this but in result i dont watch normale table
@shilpakapletiya578
@shilpakapletiya578 5 месяцев назад
I tried below code df = data.apply(lambda x: pd.factorize(x)[0]) and it worked it converted all the catagorial values to numerical and returned a new dataset.
@macharlajagapatibabu2654
@macharlajagapatibabu2654 Год назад
thankyou sir it is helps alot
Далее
Data Cleaning Part 2on bankcsv
9:52
Просмотров 1,1 тыс.
Handling categorical data
11:13
Просмотров 11 тыс.
Voy shetga man aralashay | Million jamoasi
00:56
Просмотров 161 тыс.
Python Tutorial: Dealing with categorical features
5:06