0

I have a data frame that looks like:

         CreateDate                Store       Orders_am        Orders_pm
0       2018-01-21                  2001           56               2
1       2018-01-21                  2002           51               4
2       2018-01-21                  2003           85               0

dtypes for the data frame are:

CreateDate        datetime64[ns]
Store             int64
Orders_am         int64
Orders_pm         int64

I'm trying to create a simple plot using the following:

plt.plot(df.groupby("Store").plot(x="CreateDate", y="Orders_am"))

But it's throwing the following error:

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

I'm assuming that it's choking on CreateDate - but I can't figure out how to solve it.

2
  • remove plt.plot() Commented Feb 21, 2018 at 16:56
  • df.pivot(index='CreateDate',columns='Store',values='Orders_am').plot(kind='bar') Commented Feb 21, 2018 at 17:08

1 Answer 1

1

pandas is more than just a library to make some good formatting. This is also a wrapper for matplotlib. pandas is, in other words, a higher level of abstraction for matplotlib. Doing df.groupby("Store").plot(x="CreateDate", y="Orders_am") should be enough.

However, if you would have wanted to use plt.plot(), you could have done it like any other plot, and specify the Xs and Ys into the function, such as, for instance...

store = df.groupby("Store")
plt.plot(store['CreateDate'], store['Orders_am'])
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the great explanation! This solved it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.