1

There is a column named 'country' and I want a column that is 'abc' <= the first two chars of 'country'.

In pseudocode:

df['abc'] = df['country'][0:2]

Of course this does not work.

iacob
  • 14,010
  • 5
  • 54
  • 92
jkally
  • 798
  • 2
  • 8
  • 32

1 Answers1

0

You want:

df['abc'] = df['country'].str[:2]
iacob
  • 14,010
  • 5
  • 54
  • 92