Skip to content Skip to sidebar Skip to footer

KeyError: 'column_name'

I am writing a python code, it should read the values of columns but I am getting the KeyError: 'column_name' error. Can anyone please tell me how to fix this issue. import numpy

Solution 1:

Asumming 'C:\Users\Desktop\data.csv' contains the following data

Distance_Feature Speeding_Feature
1   2
3   4
5   6
 ...

Change

df = pd.read_csv(r'C:\Users\Desktop\data.csv')

to

    df = pd.read_csv("data.txt",names=["Distance_Feature","Speeding_Feature"],sep= "\s+|\t+|\s+\t+|\t+\s+",header=1) 
    # Here it is assumed white space separator, if another separator is used change `sep`.

Post a Comment for "KeyError: 'column_name'"