Week 10 : Pandas: dropping index column

Hi
I have used below method to add row.Now I couldn’t drop the row as it is showing new_col not found in axis
df[‘new_col’]=100
df.set_index(‘new_col’,inplace=True)
df.drop(‘new_col’)

set_index will make ‘new_col’ as the index column and before you drop index column, you will need to reset index first.

df['new_col'] = 100
df.set_index('new_col', inplace = True)
df.reset_index(inplace=True) #reset index
df.drop('new_col', axis=1) #now you can drop the column
2 Likes