# How to measure the correlation between categorical variables and a continuous variable

I have the following list of the names of the categorical variables in my dataset:

categorical_columns = ['MSSubClass', 'MSZoning', 'LotShape', 'LandContour', 'LotConfig', 'Neighborhood', 'Condition1',
'Condition2', 'BldgType', 'HouseStyle', 'RoofStyle', 'RoofMatl', 'Exterior1st', 'Exterior2nd',
'Foundation', 'Heating', 'Electrical', 'Functional', 'GarageType', 'PavedDrive', 'Fence',
'MiscFeature', 'SaleType', 'SaleCondition', 'Street', 'CentralAir']


in this function definition, I am one-hot encoding each column with the help of a for loop:

def feature_encoding(df, categorical_list):

# One Hot Encoding the columns gathered in categorical_columns
for col in categorical_list:

# take one-hot encoding
OHE_sdf = pd.get_dummies(df[categorical_list])

# drop the old categorical column from original df
df.drop(col, axis = 1, inplace = True)

# attach one-hot encoded columns to original dataframe
df = pd.concat([df, OHE_sdf], axis = 1, ignore_index = True)


I don't want to use all of these columns in my training so now I am at the dimensionality reduction phase of my work. I want to measure the correlation between each of these columns and my SalePrice variable (numerical) and weed out the columns with low correlation.

I've read that Chi-square test is generally used for measuring the correlation of categorical variables but I have not seen an implementation where it was a list of categorical variables vs a continuous variable.

As an aside, you don't need to use a for loop for your encoding - get_dummies has the parameter columns which allows the user to specify which columns are encoded.
{"ft_lang_label":"__label__en","ft_lang_prob":0.6955051,"math_prob":0.7794429,"size":1439,"snap":"2020-45-2020-50","text_gpt3_token_len":350,"char_repetition_ratio":0.14216028,"word_repetition_ratio":0.0,"special_character_ratio":0.23697011,"punctuation_ratio":0.17355372,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9533148,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-10-23T22:05:48Z\",\"WARC-Record-ID\":\"<urn:uuid:015222a4-d4c1-4e76-bb40-0c9dcfda5d71>\",\"Content-Length\":\"147001\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:325f8761-f6dd-4ee2-a6df-e3c4ac8b42bc>\",\"WARC-Concurrent-To\":\"<urn:uuid:d8f6ba99-f11e-428e-969a-9be9574babbd>\",\"WARC-IP-Address\":\"151.101.1.69\",\"WARC-Target-URI\":\"https://datascience.stackexchange.com/questions/55331/how-to-measure-the-correlation-between-categorical-variables-and-a-continuous-va\",\"WARC-Payload-Digest\":\"sha1:JI2Y5PA3KRHEYEXDM722BKO6S33AWDVX\",\"WARC-Block-Digest\":\"sha1:JNNJLNKILT7YJCUSZRMLX4IPAHR3PHQI\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-45/CC-MAIN-2020-45_segments_1603107865665.7_warc_CC-MAIN-20201023204939-20201023234939-00265.warc.gz\"}"}