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...

derAl
  • 1

2 Answers2

1

you can use

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

to get the result

Sreekiran A R
  • 3,123
  • 2
  • 20
  • 41
0

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

df1 = df.loc[:, ['a', 'c]]
Loochie
  • 2,414
  • 13
  • 20