我在将数据加载到数据框并自动转换为分类变量时遇到了以下错误。
df = pd.read_csv(filepath_or_buffer=filename, header=0, index_col=False, usecols=['col1', 'col2', 'col3'], dtype={'col1': int, 'col2': 'category', 'col3': float})
TypeError: 不理解的数据类型 “category”
回答:
目前尚未实现此功能,但您可以使用以下解决方法:
dtype={'col1': int, 'col2': pd.CategoricalDtype(['cat1', 'cat2', 'cat3']), 'col3': float}
这里仍然是一个未完成的功能请求