欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Pandas創(chuàng)建DataFrame提示:type?object?'object'?has?no?attribute?'dtype'解決方案

 更新時間:2023年02月07日 15:35:09   作者:779醒  
Pandas數(shù)據(jù)幀(DataFrame)是二維數(shù)據(jù)結構,它包含一組有序的列,每列可以是不同的數(shù)據(jù)類型,這篇文章主要給大家介紹了關于Pandas創(chuàng)建DataFrame提示:type?object?‘object‘?has?no?attribute?‘dtype‘的解決方案,需要的朋友可以參考下

發(fā)現(xiàn)問題

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默認為空時

出現(xiàn)type object ‘object’ has no attribute 'dtype’告警

原因分析:

創(chuàng)建DataFrame時,data字段為空

會默認創(chuàng)建一個空字典作為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函數(shù)中:

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函數(shù)位于

D:\Users\。。。\Anaconda3\envs\Python3.7\Lib\site-packages\pandas\core\internals\construction.py

參考Python3.9環(huán)境中pandas(版本1.2.5)

同名函數(shù)(D:\Users\。。。\Anaconda3\envs\Python3.7\Lib\site-packages\pandas\core\internals\construction.py)寫法

nan_dtype = np.dtype(object)

可見該問題應該是pandas(版本0.25.3)的bug

總結

到此這篇關于Pandas創(chuàng)建DataFrame提示:type object 'object' has no attribute 'dtype'解決方案的文章就介紹到這了,更多相關Pandas創(chuàng)建DataFrame報錯內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論