2

Look at the following code:

import pandas as pd
data = pd.read_csv("list.csv")
class_names = data.classname.unique()
for ic in class_names:
print(data['classname' == ic])

It says "KeywordError: False" at print(data['classname' == ic])

But it prints the output if classname value is given directly as shown below

print(data['classname'] == 'c1')

What could be the problem?

1
  • 3
    You put the bracket in a wrong position. Must be data['classname']==ic Commented Jan 9, 2019 at 5:28

2 Answers 2

2

The location of the square bracket is placed in the wrong place.

print(data['classname'] == ic)
Sign up to request clarification or add additional context in comments.

Comments

1

If you want to print data related to a particular classname try:

for ic in class_names:
    print(data[data['classname'] == ic]])

It will return the dataframe with the ic classname

data['classname']==ic will only return a boolean series

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.