成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁技術(shù)文章
文章詳情頁

python報(bào)錯(cuò): 'list' object has no attribute 'shape'的解決

瀏覽:103日期:2022-07-17 13:23:48

numpy.array可使用 shape。list不能使用shape。

可以使用np.array(list A)進(jìn)行轉(zhuǎn)換。

(array轉(zhuǎn)list:array B B.tolist()即可)

補(bǔ)充知識(shí):Pandas使用DataFrame出現(xiàn)錯(cuò)誤:AttributeError: ’list’ object has no attribute ’astype’

在使用Pandas的DataFrame時(shí)出現(xiàn)了錯(cuò)誤:AttributeError: ‘list’ object has no attribute ’astype’

代碼入下:

import pandas as pdpop = {’Nevada’: {2001: 2.4, 2002: 2.9},’Ohio’: {2000: 1.5, 2001: 1.7, 2002: 3.6}}pd.DataFrame(pop, index=[2001, 2002, 2003])

錯(cuò)誤提示如下:

python報(bào)錯(cuò):

原因:可能是Pandas版本問題,語法格式不正確。

解決辦法:將代碼寫成如下格式,再次運(yùn)行,沒有報(bào)錯(cuò)。

pd.DataFrame(pop,columns=[’Nevada’, ’Ohio’],index=[2001,2002,2003])#或者也可以寫成下面這樣:pd.DataFrame(pop,index=pd.Series([2001,2002,2003]))

以上這篇python報(bào)錯(cuò): ’list’ object has no attribute ’shape’的解決就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程