0

I have a DataFrame called df want to iterate the columns_to_encode list and get the value of df.column but I'm getting the following error (as expected). Any idea about how cancould I do it?

columns_to_encode = ['column1','column2','column3']

for column in columns_to_encode:
    df.column 

AttributeError: 'DataFrame' object has no attribute 'column'
2
  • 1
    slight chagne to your code - do df[column] .dot notation is discouraged for selecting columns Commented Dec 12, 2021 at 15:11
  • ohh true!! How can I miss that! thanks! @Umar.H Commented Dec 12, 2021 at 15:12

1 Answer 1

1

Try this code, this will solve your issue:

columns_to_encode = ['column1','column2','column3']

for column in columns_to_encode:
    df[column]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.