Python TypeError: float() argument must be a string or a number, not 'Timestamp'
Dung Do Tien
Jun 15 2021
371
I have a dataframe, it seems to look like below:
id username pass createddate status
1 test 123 2021-03-09 1
Now I get data from that dataframe with some line of code:
item["id"].fillna(0, inplace=True)
item["username"].fillna("missing")
item["pass"].fillna("missing")
item["status"].fillna(-1, inplace=True)
item['createddate'] = pd.to_datetime(item.date)
columns = item.columns.tolist()
columns = [c for c in columns if c not in ["test"]]
But when run this code I get an error
C:\Users\SnehaPriya\Anaconda2\lib\site-packages\sklearn\utils\validation.pyc in check_array(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
371 force_all_finite)
372 else:
--> 373 array = np.array(array, dtype=dtype, order=order, copy=copy)
374
375 if ensure_2d:
TypeError: float() argument must be a string or a number, not 'Timestamp'
Please help me how to resolve this issue?
Have 1 answer(s) found.
-
đ-33
đặng thái sơn Jun 15 2021
I think the message error is very clear, you need to cast it to DateTime datatype. see example:
columns = [c for c in columns if c not in ["test", 'date']]
I hope it useful for you!
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.