我厌倦了将专栏更改为catgeory使用http://pandas.pydata.org/pandas-docs/stable/categorical.html中的文档
df = pd.DataFrame({'A':[1,2,3,4,5], 'B':['a','b','c','d','e'], 'C':['A','B','A','B','A']})
df['C']=df['C'].astype('category')
Run Code Online (Sandbox Code Playgroud)
如果我尝试通过类别
df['C']=df['C'].astype('category',categories=['A','B'])
Run Code Online (Sandbox Code Playgroud)
说错了
TypeError: _astype() got an unexpected keyword argument 'categories'
Run Code Online (Sandbox Code Playgroud)
什么是将类别传递给的正确方法astype()?
pandas ×1