Link to home
Start Free TrialLog in
Avatar of Maria Qureshi
Maria Qureshi

asked on

Why is this code wrong?

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
Avatar of Flabio Gates
Flabio Gates

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.
ASKER CERTIFIED SOLUTION
Avatar of Flabio Gates
Flabio Gates

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Maria Qureshi

ASKER

df is data frame  (my set of data)
Avatar of Norie
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: