#πŸ”’ remove a column from a pandas df and save it to a list?

9 messages Β· Page 1 of 1 (latest)

distant hill
#

I have a df of data with the 0th column being a label column. I want to save this 0th column to a list.

I tried this, but it just gives me a dataframe without the specified list (which now that I look at it, makes sense).

my_vars = df.drop(df.columns[0], axis=1).to_numpy().to_list()

is there anyway to do a nice neat one-liner that does achieve the intended result?

dull windBOT
#

@distant hill

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.

mental hatch
#

or df.iloc[:,0].to_list(), I guess

distant hill
#

Lol im so dumb ty

#

Ill report back

#

!close

dull windBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.