0

I have a list of columns for which I have ensured that the data types are correct:

Date1 Date2 Geleverde Kg Oderhvh
2021-03-02 2021-03-01 3000.0 3000.0
2021-03-02 2021-03-04 15000.0 15000.0

I changed the datatypes (note: categorical and numerical refer to a list of column names):

orders[categorical] = orders[categorical].astype('str')
orders[numeric_non_date] = orders[numeric_non_date].values.astype(float)

The schema looks correct

enter image description here

However, when I make a kde plot, I get a type error:

ax = sns.kdeplot (data = orders, x = "Geleverde Kg")

TypeError: cannot astype a datetimelike from [datetime64[ns]] to [float64]

What is going on here? This feature doesn't have a datetime datatype, so why am I getting this error?

brenda89
  • 99
  • 9
  • Please [do not post images](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question) of your data or error messages. You can include [code that creates a dataframe or the output of `print(df)`](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) (or of a few rows and columns that allow to reproduce the example) – Cimbali Jun 28 '21 at 13:25
  • Also if you specify data and x but not y, it’s likely seaborn will try to plot all columns including your datetime columns `Leveringsdatum` etc. – Cimbali Jun 28 '21 at 13:27
  • Hi, I have included two lines of data. Hopefull that helps. – brenda89 Jun 28 '21 at 13:47
  • For a kde plot you only have to define an X column, so that should not be the problem. It works perfectly fine on other dataeets I work on, so it must have soemthing to do with the data. – brenda89 Jun 28 '21 at 13:48
  • Do you get the same error with `sns.kdeplot(orders['Geleverde Kg'])` ? – Cimbali Jun 28 '21 at 14:17
  • Not the same error, but another error : TypeError: kdeplot() missing 1 required positional argument: 'data' – brenda89 Jun 28 '21 at 15:09
  • Then `sns.kdeplot(data=orders[['Geleverde Kg']], x=['Geleverde Kg'])` − basically remove the other columns from the equation. Also my kdeplot is fine with having just one column passed in, you might want to add versions of seaborn / pandas / numpy / python into your post. – Cimbali Jun 28 '21 at 15:37

0 Answers0