0

How can I select columns which are not consecutive?

e.g.

index  a   b   c
1      2   3   4
2      3   4   5

How do I select 'a', 'c' and save it in to df1?

df1 = df.log[:, 'a''c'] but it doesn't work...

3

2 Answers 2

1

you can use

df1=df[['a','c']]

to get the result

Sign up to request clarification or add additional context in comments.

Comments

0

First of all I believe there is a typo. Your code should be

df1 = df.loc[:, ['a', 'c]]

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.