簡體   English   中英

查找條目為 arrays 的 DataFrame 列的最小最大值

[英]Find the min max value of a column of a DataFrame whose entries are arrays

我想找到由數組條目組成的列的最小最大值。 然而我發現我的代碼是合理的

  error min_=100
  max_=-100
  for id in range(len(df)):
      if np.min(df['color'].iloc[id]) < min_:
         np.min_=min(df['color'].iloc[id])
      if np.max(df['color'].iloc[id]) > max_:
         np.max=np.max(df['color'].iloc[id])

我得到錯誤

'numpy.float32' object is not callable

我該如何解決?

      if np.max(df['color'].iloc[id]) > max_:
         np.max=np.max(df['color'].iloc[id])

問題是您將np.max分配為np.max(df['color'].iloc[id])的結果,它在第一個循環中返回numpy.float32

在下面的循環中,在if語句中調用了np.max(..) ,但是, np.max之前已設置為numpy.float32 這意味着您正在調用類似3.4(df['color'].iloc[id])的內容,因此會發生錯誤。

您可以使用Series.min()Series.min()來獲取值的最小值/最大值

minimum = df['color'].min()

暫無
暫無

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

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