-3
rfm = df3.groupby('CustomerID').agg({
    'InvoiceNo' : lambda num: len(num),
    'TotalSum' : lambda price: price.sum(), 
    'InvoiceDay': lambda x: ref_date- x.max()})

rfm.rename(columns={
    'InvoiceNo' : 'Frequency',
    'TotalSum' : 'Monetary', 
    'InvoiceDay': 'Recency'
}, inplace=True)

rfm['Recency'] = rfm['Recency'].dt.days

rfm.hist()
plt.show()

It keeps showing this error, I don't know what I'm doing wrong here:

TypeError: 'NoneType' object is not callable

I was expecting a histogram plot of the 3 different variables. If I don't have rfm.hist(column= 'Recency'), it still shows the same error. What is the issue here?

These are the dtypes:

Frequency      int64
Monetary     float64
Recency        int64

Output exceeds the size limit. Open the full output data in a text editor

TypeError Traceback (most recent call last) File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/getlimits.py:459, in finfo.new(cls, dtype) 458 try: --> 459 dtype = numeric.dtype(dtype) 460 except TypeError: 461 # In case a float instance was given

TypeError: 'NoneType' object is not callable

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last) /Users/Downloads/Unclassified Learning/Unclassified Learning.ipynb Cell 25 in <cell line: 2>() 1 rfm.hist() ----> 2 plt.show()

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/pyplot.py:389, in show(*args, **kwargs) 345 """ 346 Display all open figures. 347 (...) 386 explicitly there. 387 """ 388 _warn_if_gui_out_of_main_thread() ... --> 462 dtype = numeric.dtype(type(dtype)) 464 obj = cls._finfo_cache.get(dtype, None) 465 if obj is not None:

TypeError: 'NoneType' object is not callable

shim
  • 1
  • 1

1 Answers1

0

Still trying to figure out what moment it happens as we need the whole error log. But that error is trying to tell you that you are invoking a method on a None type. Meaning that some of the attributes return None, and you are still trying to access them.

To debug, recommend checking the pandas DataFrame first, printing out rfm.head().

Secondly, if this is happening while calling hist(), probably some of the underlying data is None, and might be worth investing some time into cleaning up these None rows, or filling them up with something.

Warkaz
  • 845
  • 6
  • 18
  • Hi, I see. I have included the error log, could you help me take a look? I would really appreciate it thank you! Also I am having the same error when importing KMeans from sklearn.cluster – shim Dec 03 '22 at 15:53
  • @shim this seems to be happening while calling .hist(), which in turn calls numpy. Still suspect that the underlying dataframe does have some None type values. Can you verify this `df[df['Recency'].isnull()]` for example (check more at https://stackoverflow.com/questions/45117272/pandas-filtering-none-values) – Warkaz Dec 03 '22 at 16:07