[英]Pandas Series TypeError and ValueError when using datetime
[英]ValueError when creating a Series
當我運行時:
ser = pd.Series ( data =[ 100, 'Ninguno', 300, 'Texto', 5.3], index =[ 'pablo', 'juan', 'pedro', 'enrique'])
ser
結果給了我錯誤:
ValueError:傳遞值的長度為 5,索引意味着 4。
pandas 系列只是一個具有索引的列表或數組。 您在上面的調用中傳遞了索引和數據,但是您的索引與數據的長度不同,所以這就是問題所在。 下面,我在索引中添加了另一個元素以顯示成功創建。
從你的數據來看,你想制作一個系列還不清楚嗎?
In [2]: data = [100, 'Ninguno', 300, 'Texto', 5.3]
In [3]: index = [ 'pablo', 'juan', 'pedro', 'enrique', 'other']
In [4]: ser = pd.Series(data=data, index=index)
In [5]: ser
Out[5]:
pablo 100
juan Ninguno
pedro 300
enrique Texto
other 5.3
dtype: object
In [6]: ser['pedro']
Out[6]: 300
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.