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
  • 20,084
  • 6
  • 92
  • 119
jkally
  • 794
  • 2
  • 9
  • 35

1 Answers1

0

You want:

df['abc'] = df['country'].str[:2]
iacob
  • 20,084
  • 6
  • 92
  • 119