Tags:348-5 'dete_resignations' is not defined

Screen Link:
https://app.dataquest.io/jupyter/notebooks/notebook/Employee%20Exit%20Surveys.ipynb
My Code:

What I expected to happen: I would get counts of the unique values

What actually happened:

NameError: name 'dete_resignations' is not defined

I restarted and reran the kernel several times and am still getting the same error.

Hello @vroomvroom. I cannot see your code.

My apologies, here is the code I wrote:
dete_resignations['cease_date'].value_counts()
https://app.dataquest.io/jupyter/notebooks/notebook/Employee%20Exit%20Surveys.ipynb

That line of code is correct. It is more likely that the problem is in the code you used to create dete_resignations. Can you share it?

Here are all of the codes

import pandas as pd
import numpy as np
dete_survey = pd.read_csv("dete_survey.csv")
tafe_survey = pd.read_csv("tafe_survey.csv")
dete_survey.info()
tafe_survey.info()
dete_survey.head()
tafe_survey.head()
dete_survey.isnull()
tafe_survey.isnull()
dete_survey.isnull().sum()
tafe_survey.isnull().sum()
dete_survey = pd.read_csv("dete_survey.csv", na_values='Not Stated')
dete_survey.columns
tafe_survey.columns
dete_survey_updated = dete_survey.drop(dete_survey.columns[28:49], axis=1)
tafe_survey_updated = tafe_survey.drop(tafe_survey.columns[17:66], axis=1)
dete_survey_updated.columns = dete_survey_updated.columns.str.lower().str.strip().str.replace(' ','_')
dete_survey_updated.columns
tafe_survey_updated.columns
tafe_survey_updated = tafe_survey_updated.rename({"Record ID":"id", "CESSATION YEAR":"cease_date", "Reason for ceasing employment":"separationtype", "Gender. What is your Gender?":"gender", "CurrentAge. Current Age":"age", "Employment Type. Employment Type":"employment_status", "Classification. Classification":"position", "LengthofServiceOverall. Overall Length of Service at Institute (in years)":"institute_service", "LengthofServiceCurrent. Length of Service at current workplace (in years)":"role_service"}, axis=1)
tafe_survey_updated.columns
dete_survey_updated['separationtype'].value_counts()
tafe_survey_updated['separationtype'].value_counts()
dete_resignatons = dete_survey_updated[dete_survey_updated['separationtype'] == 'Resignation'].copy()
tafe_resignations = tafe_survey_updated[tafe_survey_updated['separationtype'] == 'Resignation'].copy()
dete_resignations['cease_date'].value_counts()```

There’s a typo in your code.

When you created dete_resignations, you typed dete_resignatons instead, without the "i". That’s why the error says dete_resignations is not defined.

1 Like

I see now, thank you very much!

1 Like

Is there a way we would know that resignations may be spelled lowercase in the separationtype column and so we would know to account for this in the code
dete_survey_updated['separationtype'] = dete_survey_updated['separationtype'].str.split('-').str[0] ? Also, how is this code capitalizing resignation? I understand it splits the words into lists. Doesn’t it affect all of the words?

You can transform it to lowercase, then you will be sure:

dete_survey_updated['separationtype'] = dete_survey_updated['separationtype'].str.lower()

You can also check the unique values in this column and see if it is lowercase or not:

dete_survey_updated['separationtype'].unique()

It isn’t.

Yes, and then it selects the first element of the list.

It affects all rows in the column by splitting and selecting the first element.

1 Like