简体   繁体   中英

python pandas function object has no attribute min

Trying to find recency but getting error

AttributeError: 'function' object has no attribute 'min'

Code:

#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()

A pandas DataFrame has a diff method. To access the column named 'diff' you can use:

df = pd.DataFrame(recency.groupby('CustomerID')['diff'].min())

Or if you want to stick with dot notation, you can give the column a different name:

recency['Diff'] = maximum - recency.InvoiceDate

df = pd.DataFrame(recency.groupby('CustomerID').Diff.min())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM