簡體   English   中英

Pandas python 在 IndexError 中解決什么

[英]Pandas python what to solve in IndexError

當我嘗試從ListB ListA每個元素的出現次數時,我收到以下錯誤。

 ListA = [*range(0,10000000, 1)] ListB = [5,4,778,577,369,1147, 7851387,115547,...] count_arr = np.bincount(ListB) Number_of_counts = [count_arr[x] for x in ListA]

我收到以下錯誤,我不知道出了什么問題,因為ListA只是一個數字范圍。

 IndexError Traceback (most recent call last) <ipython-input-18-2f121c135a65> in <module> 1 count_arr = np.bincount(ListA) ----> 2 Number_of_counts = [count_arr[x] for x in ListB] <ipython-input-18-2f121c135a65> in <listcomp>(.0) 1 count_arr = np.bincount(ListB) ----> 2 Number_of_counts = [count_arr[x] for x in ListA] IndexError: index 1715766 is out of bounds for axis 0 with size 1715766

ListA's長度大於count_arr的長度。 因此,當您使用ListA的索引遍歷count_arr時,您會得到錯誤。 它們的長度應該相同

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM