0

I am taking an online course. 'bikesharing_data' is the name of the pandas object and 'workingday' is the name of the column in that data frame. The tutor wants to divide the dataset into two samples and divides the 'workingday' into ([0, 1]) groups. This is what she wrote:

sample_01 = bikesharing_data[(bikesharing_data['workingday'] == 1)]

sample_02 = bikesharing_data[(bikesharing_data['workingday'] == 0)]

My query is if I divide the sample as follows:

sample_01 = bikesharing_data['workingday' == 1]

it gives me KeyError. I understand what KeyError is but why does it throw a key error?

Tom Ron
  • 5,906
  • 3
  • 22
  • 38

1 Answers1

0
'workingday' == 1

This produces a boolean value. So for your example, this would be equivalent to calling sample_01 = bikesharing_data[False]'

as a string does not equal 1. If False is not a key in your set, you get a KeyError. You probably want to use an index as your key, not a boolean.

Groger
  • 532
  • 3
  • 15