Why is this code wrong?

Maria Qureshi
Maria Qureshi used Ask the Experts™
on
bins = [0, 10, 20, 30, 40, 50, 60, 70, 80]

df['AgeBin'] = pd.cut(df['Age'], bins)

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-16-0750c69cbf65> in <module>()
      1 bins = [0, 10, 20, 30, 40, 50, 60, 70, 80]
      2
----> 3 df['AgeBin'] = {pd.cut(df['Age'], bins)}

NameError: name 'pd' is not defined
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
you need to tell python what pd is before you can use it.
Are you working your way through some tutorial? If so, you may have missed a few previous lines.
pd may be the pandas module as in
import pandas as pd

Open in new window

But what then is df? It seems to be dict-like but again is not defined in the code you posted.
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Author

Commented:
df is data frame  (my set of data)
NorieAnalyst Assistant

Commented:
So you are using pandas?
So you are using pandas?
It sure looks like she is.
Code in the following pages use pd, df, and bins:

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial