0

Getting the following error while using the summary_data_from_transaction_data utility function included within the Lifestyles python package. Using pandas version 0.2 on Google Colab.

TypeError: float() argument must be a string or a number, not 'Day'

Any help will be much appreciated.

Code:

data_summary = summary_data_from_transaction_data(data_final, customer_id_col = "CustomerID", datetime_col = "InvoiceDate", monetary_value_col = "Sales",                                               observation_period_end = "2011-12-09", freq = "D")

Stacktrace:

/usr/local/lib/python3.6/dist-packages/lifetimes/utils.py in summary_data_from_transaction_data(transactions, customer_id_col, datetime_col, monetary_value_col, datetime_format, observation_period_end, freq)
    194         summary_columns.append('monetary_value')
    195 
--> 196     return customers[summary_columns].astype("float64")
    197 
    198 

/usr/local/lib/python3.6/dist-packages/pandas/core/generic.py in astype(self, dtype, copy, errors, **kwargs)
   5880             # else, only a single dtype is given
   5881             new_data = self._data.astype(
-> 5882                 dtype=dtype, copy=copy, errors=errors, **kwargs
   5883             )
   5884             return self._constructor(new_data).__finalize__(self)

/usr/local/lib/python3.6/dist-packages/pandas/core/internals/managers.py in astype(self, dtype, **kwargs)
    579 
    580     def astype(self, dtype, **kwargs):
--> 581         return self.apply("astype", dtype=dtype, **kwargs)
    582 
    583     def convert(self, **kwargs):

/usr/local/lib/python3.6/dist-packages/pandas/core/internals/managers.py in apply(self, f, axes, filter, do_integrity_check, consolidate, **kwargs)
    436                     kwargs[k] = obj.reindex(b_items, axis=axis, copy=align_copy)
    437 
--> 438             applied = getattr(b, f)(**kwargs)
    439             result_blocks = _extend_blocks(applied, result_blocks)
    440 

/usr/local/lib/python3.6/dist-packages/pandas/core/internals/blocks.py in astype(self, dtype, copy, errors, values, **kwargs)
    557 
    558     def astype(self, dtype, copy=False, errors="raise", values=None, **kwargs):
--> 559         return self._astype(dtype, copy=copy, errors=errors, values=values, **kwargs)
    560 
    561     def _astype(self, dtype, copy=False, errors="raise", values=None, **kwargs):

/usr/local/lib/python3.6/dist-packages/pandas/core/internals/blocks.py in _astype(self, dtype, copy, errors, values, **kwargs)
    641                     # _astype_nansafe works fine with 1-d only
    642                     vals1d = values.ravel()
--> 643                     values = astype_nansafe(vals1d, dtype, copy=True, **kwargs)
    644 
    645                 # TODO(extension)

/usr/local/lib/python3.6/dist-packages/pandas/core/dtypes/cast.py in astype_nansafe(arr, dtype, copy, skipna)
    727     if copy or is_object_dtype(arr) or is_object_dtype(dtype):
    728         # Explicit copy, or required since NumPy can't view from / to object.
--> 729         return arr.astype(dtype, copy=True)
    730 
    731     return arr.view(dtype)

TypeError: float() argument must be a string or a number, not 'Day'

Sample data in the data_final df and associated dtypes are as per the attachments.

sample data

dtypes

Thanks for any help.

finlytics-hub
  • 164
  • 1
  • 9
  • Does this help you? https://stackoverflow.com/questions/41256626/pandas-typeerror-float-argument-must-be-a-string-or-a-number – Jakov Gl. May 26 '20 at 09:51
  • thanks @JakovGl. I had went through that question before posting but it didn't help my particular case. Anyways, the problem was resolved after I updated lifetimes to the latest 0.11.1 version in Colab! – finlytics-hub May 26 '20 at 10:14

1 Answers1

1

Apologies folks - I was able to resolve my issue after updating the Lifetimes package to the latest 0.11.1 version in Colab!

finlytics-hub
  • 164
  • 1
  • 9