ValueError: cannot convert to 'int64'-dtype NumPy array with missing values. Specify an appropriate 'na_value' for this dtype.

目录

ValueError: cannot convert to 'int64'-dtype NumPy array with missing values. Specify an appropriate 'na_value' for this dtype.

问题:

解决:

完整错误:


问题:

注意,使用Int64可,此处I大写,但是在进入算法模型的时候又会出现问题,包庇了缺失值;

df_in['label'] = df_in['label'].astype('Int64')

使用小写int64,发生错误;

df_in = df_origin
#'int64'
df_in['label'] = df_in['label'].astype('int64')

解决:

正确的做法在缺失值填充之后再进行格式转换处理;

df_in = df_origin
#'int64'
# df_in['label'] = df_in['label'].astype('int64')df_in = df_in.fillna(0)
df_in['label'] = df_in['label'].astype('int64')

完整错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-60-f515db1e7d91> in <module>
      1 df_in = df_origin
      2 #'Int64'
----> 3 df_in['label'] = df_in['label'].astype(np.int64)

D:\anaconda\lib\site-packages\pandas\core\generic.py in astype(self, dtype, copy, errors)
   5875         else:
   5876             # else, only a single dtype is given
-> 5877             new_data = self._mgr.astype(dtype=dtype, copy=copy, errors=errors)
   5878             return self._constructor(new_data).__finalize__(self, method="astype")
   5879

D:\anaconda\lib\site-packages\pandas\core\internals\managers.py in astype(self, dtype, copy, errors)
    629         self, dtype, copy: bool = False, errors: str = "raise"
    630     ) -> "BlockManager":
--> 631         return self.apply("astype", dtype=dtype, copy=copy, errors=errors)
    632 
    633     def convert(

D:\anaconda\lib\site-packages\pandas\core\internals\managers.py in apply(self, f, align_keys, ignore_failures, **kwargs)
    425                     applied = b.apply(f, **kwargs)
    426                 else:
--> 427                     applied = getattr(b, f)(**kwargs)
    428             except (TypeError, NotImplementedError):
    429                 if not ignore_failures:

D:\anaconda\lib\site-packages\pandas\core\internals\blocks.py in astype(self, dtype, copy, errors)
    646         if self.is_extension:
    647             try:
--> 648                 values = self.values.astype(dtype)
    649             except (ValueError, TypeError):
    650                 if errors == "ignore":

D:\anaconda\lib\site-packages\pandas\core\arrays\integer.py in astype(self, dtype, copy)
    472             na_value = lib.no_default
    473 
--> 474         return self.to_numpy(dtype=dtype, na_value=na_value, copy=False)
    475 
    476     def _values_for_argsort(self) -> np.ndarray:

D:\anaconda\lib\site-packages\pandas\core\arrays\masked.py in to_numpy(self, dtype, copy, na_value)
    219             ):
    220                 raise ValueError(
--> 221                     f"cannot convert to '{dtype}'-dtype NumPy array "
    222                     "with missing values. Specify an appropriate 'na_value' "
    223                     "for this dtype."

ValueError: cannot convert to 'int64'-dtype NumPy array with missing values. Specify an appropriate 'na_value' for this dtype.

ValueError: cannot convert to ‘int64‘-dtype NumPy array with missing values. Specify an appropriate相关推荐

  1. Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.int64).

    ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.int64). 检查你的训 ...

  2. model.fit()模型编译时报错:ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type

    model.fit()模型编译时报错:ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type ...

  3. ValueError: At least one stride in the given numpy array is negative解决方案

    ValueError: At least one stride in the given numpy array is negative, and tensors with negative stri ...

  4. Debug Tensorflow: TypeError: Cannot convert a symbolic Keras input/output to a numpy array.

    问题 'Cannot convert a symbolic Keras input/output to a numpy array. ' TypeError: Cannot convert a sym ...

  5. ValueError: At least one stride in the given numpy array is negative

    问题: ValueError: At least one stride in the given numpy array is negative, and tensors with negative ...

  6. PIL.Image convert to numpy array

    当使用PIL.Image读取图像时,如果直接使用numpy.array()转换会出现错误: lst = list() for file_name in os.listdir(dir_image):im ...

  7. 解决pandas:ValueError: Cannot convert non-finite values (NA or inf) to integer

    解决pandas:ValueError: Cannot convert non-finite values (NA or inf) to integer 目录 解决pandas:ValueError: ...

  8. matplotlib figure转为numpy array或者PIL图像进行显示

    matplotlib figure转为numpy array或者PIL图像进行显示 实现将matplotlib绘制的图像转换为numpy数组,并使用PIL或者OpenCV进行显示 参考资料:http: ...

  9. php excel转数组,php将excel数据转换为3d数组(php convert excel data into 3d array)

    php将excel数据转换为3d数组(php convert excel data into 3d array) 我有一个excel文件,其数据是一个3d数组. 我正在使用PHPExcel Objec ...

最新文章

  1. 0x11.基本数据结构 — 栈与单调栈
  2. Java oracle 超出打开游标的最大数
  3. python---方法解析顺序MRO(Method Resolution Order)<以及解决类中super方法>
  4. select,table,form
  5. 2021年宝鸡中学高考成绩查询,宝鸡各高中2020年高考喜报成绩一览
  6. 编辑流程图_如何使用ProcessOn快速绘制一张高颜值流程图?
  7. Disturbed People(思维)
  8. java8-02-Stream-API
  9. (转)Spring中的事务操作
  10. 中国焦磷酸四钾市场趋势报告、技术动态创新及市场预测
  11. 一、RequireHttps
  12. NetSetMan特别版 网络地址切换工具
  13. 269个JavaScript工具函数,助你提升工作效率(2)
  14. 围棋人机大战属于计算机在什么方面的应用,人民日报评围棋人机大战:胜出的是我们自己...
  15. 移动前端开发人员必知必会:移动设备概述
  16. 多个excel工作簿合并_EXCEL多表、多工作簿合并拆分,随心所欲(完善版)
  17. bzoj 1260涂色 题解
  18. LeetCode-Hot100-无重复字符的最长子串
  19. 雷声大雨点小:Bakkt「见光死」了吗?
  20. 商汤的AI伴游小精灵

热门文章

  1. OKR这么好,企业可以都选择OKR吗?
  2. 一堆让人惊喜的实用工具,也许你还不知道
  3. C++赋值运算符与赋值表达式
  4. XGBoost算法原理解释(转载)
  5. 知识图谱与深度学习(新时代·技术新未来)
  6. 高分辨率、实时的手持物体360°三维模型重建结构光技术
  7. Nature回应南大花120万发特刊!被骂上热搜,南大到底委不委屈?
  8. 图像反光能被一键去除了?港科大开源RFC,仅用一个操作,强反光也能完美去除|CVPR2021...
  9. 鲁棒,抗遮挡的对柔性手抓取的物体6D姿态估计
  10. mysql 乐观锁 命令_MySQL-乐观锁