When trying to drop a column from my dataset using pandas, i get the error "['churn'] not found in axis"

Stack Overflow Asked by Utku Şenel on January 3, 2022

I want the x to be all the columns except "churn" column.
But when i do the below i get the "[‘churn’] not found in axis" error, eventhough i can see the column name when i write "print(list(df.column))"
Here is my code:

import pandas as pd
import numpy as np

df = pd.read_csv("/Users/utkusenel/Documents/Data Analyzing/data.csv", header=0)
x = df.drop(["churn"], axis=1) ## this is the part it gives the error

I am adding a snippet of my dataset as well:


One Answer

I see that your df snippet is separeted with ';' (semi colon). If that is what your actual data looks like, then probably your csv is being read wrong. Please try adding sep=';' to read_csv function.

df = pd.read_csv("/Users/utkusenel/Documents/Data Analyzing/data.csv", header=0, sep=';')

I also suggest print df.columns again and check if there is a leading or trailing whitespace in the column name for churn.

Answered by Farid Jafri on January 3, 2022

Add your own answers!

Related Questions

Red box isn’t placed as expected

1  Asked on November 4, 2021 by liya-thomas


String Comparison Javascript

2  Asked on November 4, 2021 by crimsonpython24


es5 using promise but returns defered before resolving

2  Asked on November 4, 2021 by rodney-wormsbecher


2 arrays with json problem (Node.js, Discord.js)

3  Asked on November 4, 2021 by mr-code


Is there a XAML equivalent to nameof?

2  Asked on November 4, 2021 by luxun


Multistage builds with yum

3  Asked on November 4, 2021 by vorticity


WooCommerce can’t see product variations

1  Asked on November 4, 2021 by tizio-fittizio


VScode setup with ROS and auto complete

3  Asked on November 4, 2021 by dixcipuli


Pick an account after Connect-MicrosoftTeams

4  Asked on November 4, 2021 by mauek-unak


Show local image file:///tmp/someimage.jpg

1  Asked on November 4, 2021 by dani-herrera


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir