import pandas as pd
test_df = pd.DataFrame({'Month':['January', 'February', 'March', 'March'], 'Values':[0,1,2,3]})
test_df['Month'] = pd.Categorical(test_df['Month'], categories=['January', 'February', 'March'])
test_df.set_index(['Month'])
test_df.set_index(['Month'], inplace=True)
test_df.index.add_categories(new_categories='April', inplace=True)ValueError: cannot use inplace with CategoricalIndex
inplace=True
.inplace=False
and capture the return value:test_df
= test_df.reindex(test_df.index.add_categories(new_categories='April', inplace=False))
Values Month January 0 February 1 March 2 March 3 CategoricalIndex(['January', 'February', 'March', 'March'],Note: I don't recommend setting the index to a column with duplicate values. But it's hard to recommend anything pertaining to that without more context.
categories=['January', 'February', 'March', 'April'],
ordered=False,
name='Month',
dtype='category')
--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.