Osama Hamdy
Osama Hamdy

Reputation: 13

How to type "pd.api.types.CategoricalDtype"

I have error running this code and I don't know what the problem is?

sedan_classes = ['Minicompact Cars', 'Subcompact Cars', 'Compact Cars', 'Midsize Cars', 'Large Cars']

vclasses = pd.api.types.CategoricalDtype[categories = sedan_classes, ordered = True]

fuel_econ['Vclass'] = fuel_econ['Vclass'].astype(vclasses)

The error message shows:

File "", line 3 vclasses = pd.api.types.CategoricalDtype[categories = sedan_classes, ordered = True] ^ SyntaxError: invalid syntax

Upvotes: 1

Views: 608

Answers (1)

exilour
exilour

Reputation: 556

You are trying to call a function with rectangular braces which is used for indexing. The call would be vclasses = pd.api.types.CategoricalDtype(categories = sedan_classes, ordered = True) . Check the doc here

Upvotes: 1

Related Questions