热线电话:13121318867

登录
2021-04-20 阅读量: 793
看一个数据框对象的info属性的时候出现问题

6.png

为了方便大家检索到,我把错误提示的文字版也贴出来
---------------------------------------------------------------------------TypeError                                 Traceback (most recent call last)in----> 1 df.info()d:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in info(self, verbose, buf, max_cols, memory_usage, null_counts)   2495                 if "object" in counts or self.index._is_memory_usage_qualified():   2496                     size_qualifier = "+"-> 2497             mem_usage = self.memory_usage(index=True, deep=deep).sum()   2498             lines.append(f"memory usage: {_sizeof_fmt(mem_usage, size_qualifier)}\n")   2499         fmt.buffer_put_lines(buf, lines)d:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in memory_usage(self, index, deep)   2588         )   2589         if index:-> 2590             result = Series(self.index.memory_usage(deep=deep), index=["Index"]).append(   2591                 result   2592             )d:\ProgramData\Anaconda3\lib\site-packages\pandas\core\series.py in __init__(self, data, index, dtype, name, copy, fastpath)    303                     data = data.copy()    304             else:--> 305                 data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True)    306     307                 data = SingleBlockManager(data, index, fastpath=True)d:\ProgramData\Anaconda3\lib\site-packages\pandas\core\construction.py in sanitize_array(data, index, dtype, copy, raise_cast_failure)    463                 value = maybe_cast_to_datetime(value, dtype)    464 --> 465             subarr = construct_1d_arraylike_from_scalar(value, len(index), dtype)    466     467         else:d:\ProgramData\Anaconda3\lib\site-packages\pandas\core\dtypes\cast.py in construct_1d_arraylike_from_scalar(value, length, dtype)   1459                 value = ensure_str(value)   1460 -> 1461         subarr = np.empty(length, dtype=dtype)   1462         subarr.fill(value)   1463 TypeError: Cannot interpret '' as a data type


18.png


把df.info()改为df.info就对了,结果如下

21.png

0.0000
0
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子