網站首頁 編程語言 正文
Pandas創建DataFrame提示:type?object?'object'?has?no?attribute?'dtype'解決方案_python
作者:779醒 ? 更新時間: 2023-04-12 編程語言發現問題
pandas版本0.25.3
import pandas as pd
symbol_info_columns = ['1', '持倉方向', '持倉量', '持倉收益率', '持倉收益', '持倉均價', '當前價格', '最大杠桿'] # v3
symbol_config = {'BTC': 'BTC-USDT-210924', 'LTC': 'LTC-USDT-210924', 'EOS': 'EOS-USDT-210924', 'ETH': 'ETH-USDT-210924', 'XRP': 'XRP-USDT-210924', 'FIL': 'FIL-USDT-210924'}
symbol_info = pd.DataFrame()
# dates = pd.date_range('20190101', periods=6)
# num_df = pd.DataFrame(data=np.random.randn(6, 8), index=dates, columns=symbol_info_columns)
symbol_info = pd.DataFrame(index=symbol_config.keys(), columns=symbol_info_columns)
data為空,且dtype默認為空時
出現type object ‘object’ has no attribute 'dtype’告警
原因分析:
創建DataFrame時,data字段為空
會默認創建一個空字典作為data
def __init__(self, data=None, index=None, columns=None, dtype=None, copy=False):
if data is None:
data = {}
然后初始化字典
elif isinstance(data, dict):
mgr = init_dict(data, index, columns, dtype=dtype)
init_dict函數中:
columns非空,且dtype默認為None時,會賦值nan_dtype = object
if columns is not None:
if missing.any() and not is_integer_dtype(dtype):
if dtype is None or np.issubdtype(dtype, np.flexible):
# GH#1783
nan_dtype = object
該object下無dtype方法
可能是object引用錯誤
解決方案:
pandas(版本0.25.3)init_dict函數位于
D:\Users\。。。\Anaconda3\envs\Python3.7\Lib\site-packages\pandas\core\internals\construction.py
參考Python3.9環境中pandas(版本1.2.5)
同名函數(D:\Users\。。。\Anaconda3\envs\Python3.7\Lib\site-packages\pandas\core\internals\construction.py)寫法
nan_dtype = np.dtype(object)
可見該問題應該是pandas(版本0.25.3)的bug
總結
原文鏈接:https://blog.csdn.net/chenbaixing/article/details/118872809
相關推薦
- 2022-07-12 eureka更換為nacos
- 2022-12-10 OpenMP?共享內存的并行編程框架入門詳解_C 語言
- 2022-08-30 使用Angular FormBuilder初始化新建FormGroup
- 2022-11-17 python實現excel轉置問題詳解_python
- 2022-09-15 python安裝whl文件的實戰步驟_python
- 2022-09-08 pytorch實現加載保存查看checkpoint文件_python
- 2022-05-14 Python偽隨機數模塊random詳解_python
- 2021-12-08 .net?core?api接口JWT方式認證Token_實用技巧
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支