Variable project: what comes after the dataframe name in the pd.Categorical function?

Hello, I am on question 8 of the variable project in Python for Statistics.

Converting the higher_tax column to categorical data

census[‘higher_tax’] = pd.Categorical(census[], [‘strongly disagree’, ‘disagree’, ‘neutral’, ‘agree’, ‘strongly agree’], ordered=)

I understand that the last blank will say TRUE…but I can’t for the life of me figure out what goes after (census[____] ?

This is what I have:

census[‘higher_tax’] = pd.Categorical(census**.[_____]**[‘strongly disagree’, ‘disagree’, ‘neutral’, ‘agree’, ‘strongly agree’,] ordered=TRUE)

I feel like I’ve tried everything. Hope you can help? Thanks all.

You’re almost there.

You have:

census['higher_tax'] = pd.Categorical(census['what column name goes here?'], ['strongly disagree', 'disagree', 'neutral', 'agree', 'strongly agree'], ordered=True)

ie: what column are you converting to categorical in the code above?


Hi there,

Thanks very much for this help. I am still pretty confused because this code is still returning a syntax error:

census[‘higher_tax’] = pd.Categorical(census[‘higher_tax’], [‘strongly disagree’, ‘disagree’, ‘neutral’, ‘agree’, ‘strongly agree’,] ordered=TRUE)

1 Like

Your comma is misplaced after the last item in the list. It should go outside the brackets.
Also, TRUE should be True.