Cleaning my columns

cleaing columns

AttributeErrorTraceback (most recent call last)
<ipython-input-30-fe8a0d8ef920> in <module>()
----> 1 dete_updated.columns

AttributeError: 'Index' object has no attribute 'columns'

why am i getting an error.

Replace this line with your code

What I expected to happen:

What actually happened:

Replace this line with the output/error

Your dete_updated object is not a DataFrame and therefore doesn’t have the columns attribute.

Could share more of the code and the screen link as per these guidelines?

columns_2_drop = dete.columns[28:49]
dete_updated = dete.drop(columns_2_drop, axis = 1)

that is the code before this

dete_updated.columns.str.lower().str.strip().str.replace(' ', '_')

dete_updated.head()

my columns unfortunately didnt change

dete_updated[dete_updated['SeparationType'] == ['Resignation-Other reasons','Resignation-Other employer', 'Resignation-Move overseas/interstate']

my code to select multiples rows also didnt work

Hi @ayodejiadio:

Please format your code accordingly and share the mission link so that we can better assist you.

Thanks for your understanding and cooperation.

If nothing works, then you probably made some changes in the columns. Could you share the entire notebook?

You can see how to do it in the link below.

Basics.ipynb (234.2 KB)
here is the file and where i am stucked.Thank you

Click here to view the jupyter notebook file in a new tab

1 Like

Thanks for sharing the notebook.


This is correct and the dete_updated.columns doesn’t raise any errors in your notebook.


Your columns did change:

The names of the columns are not displayed because you didn’t use the print function.


This code is incorrect. You’re trying to select all the rows of the DataFrame where the value in the SeparationType column is a specific list. None of the values in this column is equal to this list and therefore you get an empty DataFrame.

This is the correct sintaxx for this kind of filtering:

dete_updated[(dete_updated['SeparationType'] == 'Resignation-Other reasons') | 
             (dete_updated['SeparationType'] == 'Resignation-Other employer') | 
             (dete_updated['SeparationType'] == 'Resignation-Move overseas/interstate')]

Or, to be more generalistic:

df[(df['column'] == 'value1') | (df['column'] == 'value2') | (df['column'] == 'value3')]

In this case, the signal | means or.


The last cell in your notebook raises an error. The code is:

dete_resign['cease_date']

This happens because dete_resign doesn’t have a column named cease_date. In fact, dete_resign is not even a DataFrame. It’s a Series. Run type(dete_resign) and you’ll see it.

This is how you created it:

dete_resign = dete_updated['separationtype'].str.contains('Resignation').copy() 

This code only selects the separationtype column. It filters this column selecting only values with the Resignation word in it, yes, but it returns only the filtered column and not the entire DataFrame filtered by this column.

The correct code for this is:

dete_resign = dete_updated[dete_updated['separationtype'].str.contains('Resignation')].copy() 

If you use the above code then dete_resign['cease_date'] won’t raise an error.


I think that’s all. Hope it helps you.

2 Likes

Thank you for helping out.
I have a problem drawing the boxplots for separationtype column.
here is the link to the page.

This is unrelated to the problem approached in this topic.

I suggest you create a new topic and explain your problem. Make sure to post the code you’re running and the screen link as well as per these guidelines.

1 Like