为了重现问题,笔记本,数据,输出:github链接
我的数据集中有合同变量/列,看起来像这样,看起来都像数字,但它们实际上是分类的。
当使用 pandas 读取时,信息显示它被读取为 int。由于合同变量是一个类别(来自我收到的元数据)所以我手动更改了变量类型,如下所示
df['Contract'] = df['Contract'].astype('categorical')
df.dtypes # shows modified dtype now
然后我试图从pandas_profiling
. 生成的报告显示它contact
被解释为实数,即使我将类型从更改int
为str
/ category
。
# Tried both, but resulted in same.
ProfileReport(df)
df.profile_report()
你能解释解释数据类型的正确方法pandas_profiling
吗?即,将contract
变量更改为categorical
类型。