【问题标题】:StringDtype data type not understoodStringDtype 数据类型不理解
【发布时间】:2020-03-18 10:22:17
【问题描述】:

从扩展类型转换时,例如pd.Int32Dtype(),我得到TypeError: data type not understood。示例:

num_col_with_nan = num_col_with_nan.astype(pd.Int32Dtype()).astype("string")

【问题讨论】:

    标签: python pandas pandas-1.0


    【解决方案1】:

    尚不支持在扩展类型之间进行转换 - 请参阅 #22384 了解一般概述,具体请参阅 #31204 了解 StringDtype。

    作为一种解决方法,请先尝试强制转换为 str:

    num_col_with_nan = num_col_with_nan.astype(pd.Int32Dtype()).astype(str).astype("string")
    

    【讨论】:

      猜你喜欢
      • 2011-07-23
      • 2020-06-16
      • 2018-05-24
      • 2021-06-11
      • 2020-03-25
      • 1970-01-01
      • 2021-07-17
      • 1970-01-01
      • 2018-12-01
      相关资源
      最近更新 更多