how to do a left,right and mid of a string in a pandas dataframe

后端 未结 2 472
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 17:56

in a pandas dataframe how can I apply a sort of excel left(\'state\',2) to only take the first two letters. Ideally I want to learn how to use left,right and mid in a datafr

2条回答
  •  [愿得一人]
    2020-12-07 17:59

    With regards to the mid, probably a short cut code would be df['state'].str[3,5]

    this will start from the 3rd character and give you the 3rd and 4th character of the string.

提交回复
热议问题