#🔒 Need help in selecting X and y

28 messages · Page 1 of 1 (latest)

thin locust
#

Hello everyone,
I am trying to select X and y as:
X = [c for c in branches if c != 'flags']

y = (["flags"] == 1).astype(Int64)
However, the entirity of my data is mixed (some bool some int) Not sure if I can sort of go around this in y since it keeps saying it's a bool.
X is supposed to be all the cols except flags and y is when flags ==1.
Error: AttributeError: 'bool' object has no attribute 'astype'

inland sandBOT
#

@thin locust

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

worldly orchid
maiden spruce
#

Yeah error probs comes from y

thin locust
#

Yes, exactly

#

It errors at y

maiden spruce
#

["flags"]==1 evaluates to False (bool)

thin locust
#

It's a csv

worldly orchid
#

!e

result = (["flags"] == 1)
print(result)
print(type(result))
thin locust
#

the data I mean.

inland sandBOT
thin locust
#

1 is the identifier sort of for what I am looking for

#

I don't even think it's supposed to be a bool

worldly orchid
#

If you want to "convert" the values to make sure that its an integer, you apply the astype method from a Dataframe

#

!d pandas.DataFrame.astype

inland sandBOT
#

DataFrame.astype(dtype, copy=None, errors='raise')```
Cast a pandas object to a specified dtype `dtype`.
worldly orchid
#

At the moment, its not being called from a DataFrame.

worldly orchid
thin locust
#

was I supposed to df.?

worldly orchid
#

It dependsâ„¢

#

Do you have a df as a DataFrame or not?

thin locust
#

Yes

worldly orchid
#

then yes

thin locust
#

You were right thanks a lot

#

!close

inland sandBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.