python - ValueError: cannot use inplace with CategoricalIndex -


i using pandas 0.18.

this fails

 cat_fields[f[0]].add_categories(s,inplace=true) 

however docs say

inplace : boolean (default: false)

whether or not add categories inplace or return copy of categorical added categories.

am missing ?

i creating superset of categories/columns across many dataframes able concatenate them.

my error:

valueerror: cannot use inplace categoricalindex

i think need assign original column, because series.add_categories has inplace parameter , works nice.

but in categoricalindex.add_categories has inplace parameter, fails. think bug.

cat_fields[f[0]] = cat_fields[f[0]].add_categories(s) 

or:

cat_fields[f[0]] = cat_fields[f[0]].cat.add_categories(s) 

sample:

cat_fields = pd.dataframe({'a':[1,2,3]}, index=['a','d','f'])   cat_fields.index = pd.categoricalindex(cat_fields.index) cat_fields.a = pd.categorical(cat_fields.a) print (cat_fields)    a  1 d  2 f  3  s = ['b','c']  cat_fields.a.cat.add_categories(s,inplace=true)  print (cat_fields.a) name: a, dtype: category categories (5, object): [1, 2, 3, b, c]   cat_fields.index.add_categories(s,inplace=true) print (cat_fields) 

valueerror: cannot use inplace categoricalindex


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -