-1

I uploaded a dataset to jupyter notebook and did analysis using pandas, suddenly im not able to access several columns from my dataset im getting the error

"['DATE OF OCCURRENCE'] not in index"

I checked for whitespace error but even with columns without whitespace im still getting the error

i tried to run

df1 = df[['ARREST','DATE OF OCCURRENCE']]

got the above mentioned error same for 'primary description' and other columns with space but it also happened with 'IUCR' column so maybe error isnt due to white space all columns are object class Plzz help

Murtaza Haji
  • 1,093
  • 1
  • 13
  • 32

1 Answers1

1

Some of your column names have leading spaces.

Try this:

df.columns = df.columns.str.strip()
MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419