Home > Back-end >  Pandas Dataframe set Categories - The `inplace` parameter in pandas.Categorical.set_categories is de
Pandas Dataframe set Categories - The `inplace` parameter in pandas.Categorical.set_categories is de

Time:12-14

I have following statement in my code:

mcap_summary['cap'].cat.set_categories(['Large','Mid','Small','None'],inplace=True)

Which now generates a warning as: D:\Python\Python39\lib\site-packages\pandas\core\arrays\categorical.py:2630: FutureWarning: The inplace parameter in pandas.Categorical.set_categories is deprecated and will be removed in a future version. Removing unused categories will always return a new Categorical object. res = method(*args, **kwargs)

How am I suppose to write to avoid this warning and future errors?

Thanks in advance

CodePudding user response:

pandas v1.3.0 removed 'inplace' option.

so you can code like below:

mcap_summary['cap'] = mcap_summary['cap'].cat.set_categories(['Large', 'Mid', 'Small', 'None'])
  • Related