Errors for separationtype value counts

Screen Link:

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

dete_survey_updated['separationtype'].value_counts()
tafe_survey_updated["separationtype"].value_counts()

What I expected to happen:
I would get the counts of values for the separationtype series in dete_survey_updated and tafe_survey_updated. separationtype is in both dataframes.

What actually happened:
Error for dete_survey_updated is IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

Error for tafe_survey_updated is KeyError: 'separationtype'

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

Hey @vroomvroom , I can’t access the notebook because the link is broken, can you copy paste the entire code instead ? and if possible, can you give me the link to dataset ?

Yes, the link to the dataset is:
https://app.dataquest.io/jupyter/notebooks/notebook/Employee%20Exit%20Surveys.ipynb

Below is the code.

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 = dete_survey_updated.columns.str.lower().str.strip().str.replace(' ','_')
print(dete_survey_updated)
dete_survey_updated.columns
tafe_survey_updated.columns
dir(dete_survey_updated)
type(dete_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)
dete_survey_updated['separationtype'].value_counts()
tafe_survey_updated["separationtype"].value_counts()

For this problem

The error arises because there is no column with the name “separationtype”, the problem stems from here

you forgot to set inplace=“True” and put “columns=” before the set of columns. Here’s the fix

And for this error

The error arises because variable “dete_survey_updated” isn’t dataframe, the problem stems from here

from that code above, variable dete_survey_updated will be filled by list Indexes instead of Dataframe. Here’s the fix

Hope it’s help

Thanks for replying. For separationtype, I thought that was the error too but in 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) , the output dataframe includes the separationtype column.

I got another error ‘Cannot specify both ‘axis’ and any of ‘index’ or ‘columns’’ when I set inplace='True and put “columns=” before the list of columns.

dete_survey_updated.columns.str.lower().str.strip().str.replace(’ ‘,’_’) gives the error : AttributeError: ‘Index’ object has no attribute ‘columns’

I’m not sure what is the problem with the code.

I figured it out. I needed to set the renaming code equal to tafe_survey_updated. 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)