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-0750c69c bf65> 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
df['AgeBin'] = pd.cut(df['Age'], bins)
--------------------------
NameError Traceback (most recent call last)
<ipython-input-16-0750c69c
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
df is data frame (my set of data)
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: