[英]Python 'AttributeError: 'function' object has no attribute 'min''
[英]python pandas function object has no attribute min
試圖查找新近度但出現錯誤
AttributeError: 'function' object 沒有屬性 'min'
代碼:
#Generating recency function
# Filtering data for customerid and invoice_date
recency = order_wise[['CustomerID','InvoiceDate']]
# Finding max data
maximum = max(recency.InvoiceDate)
# Adding one more day to the max data, so that the max date will have 1 as the difference and not zero.
maximum = maximum + pd.DateOffset(days=1)
recency['diff'] = maximum - recency.InvoiceDate
recency.head()
df = pd.DataFrame(recency.groupby('CustomerID').diff.min())
df = df.reset_index()
df.columns = ["CustomerID", "Recency"]
df.head()
pandas DataFrame 有一個diff
方法。 要訪問名為'diff'
的列,您可以使用:
df = pd.DataFrame(recency.groupby('CustomerID')['diff'].min())
或者,如果您想堅持使用點表示法,您可以為該列指定一個不同的名稱:
recency['Diff'] = maximum - recency.InvoiceDate
df = pd.DataFrame(recency.groupby('CustomerID').Diff.min())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.