データフレーム内の列データについて、一部の文字列を切り出すことを考えます。
文字列のスライシング、とも呼ばれます。

元データ:data1

In [8]: data1.head()
Out[8]:
   age  workclass  fnlwgt     education  educational-num      marital-status  \
0   25    Private  226802          11th                7       Never-married
1   38    Private   89814       HS-grad                9  Married-civ-spouse
2   28  Local-gov  336951    Assoc-acdm               12  Married-civ-spouse
3   44    Private  160323  Some-college               10  Married-civ-spouse
4   18          ?  103497  Some-college               10       Never-married

          occupation relationship   race  gender  capital-gain  capital-loss  \
0  Machine-op-inspct    Own-child  Black    Male             0             0
1    Farming-fishing      Husband  White    Male             0             0
2    Protective-serv      Husband  White    Male             0             0
3  Machine-op-inspct      Husband  Black    Male          7688             0
4                  ?    Own-child  White  Female             0             0

   hours-per-week native-country income
0              40  United-States  <=50K
1              50  United-States  <=50K 
2              40  United-States  >50K
3              40  United-States  >50K
4              30  United-States  <=50K

str[x : y]を使う

文字列のx番目からy番目の一つ手前までの文字列がカットできます。

例1

#  'marital-status'列の頭から5文字をカットし、'marital-status2'を新規列として作成
data1['marital-status2'] = data1['marital-status'].str[0:5]

例1の結果

   age  workclass  fnlwgt     education  educational-num      marital-status  \
0   25    Private  226802          11th                7       Never-married
1   38    Private   89814       HS-grad                9  Married-civ-spouse
2   28  Local-gov  336951    Assoc-acdm               12  Married-civ-spouse
3   44    Private  160323  Some-college               10  Married-civ-spouse
4   18          ?  103497  Some-college               10       Never-married

          occupation relationship   race  gender  capital-gain  capital-loss  \
0  Machine-op-inspct    Own-child  Black    Male             0             0
1    Farming-fishing      Husband  White    Male             0             0
2    Protective-serv      Husband  White    Male             0             0
3  Machine-op-inspct      Husband  Black    Male          7688             0
4                  ?    Own-child  White  Female             0             0

   hours-per-week native-country income marital-status2
0              40  United-States  <=50K           Never
1              50  United-States  <=50K           Marri 
2              40  United-States  >50K             Marri
3              40  United-States  >50K           Marri
4              30  United-States  <=50K           Never

 

「頭から」を意味する0は、省略可能で、上記は以下のようにも書けます。

例2

#  'marital-status'列の頭から5文字をカットし、'marital-status2'を新規列として作成
data1['marital-status2'] = data1['marital-status'].str[:5]

例2の結果

   age  workclass  fnlwgt     education  educational-num      marital-status  \
0   25    Private  226802          11th                7       Never-married
1   38    Private   89814       HS-grad                9  Married-civ-spouse
2   28  Local-gov  336951    Assoc-acdm               12  Married-civ-spouse
3   44    Private  160323  Some-college               10  Married-civ-spouse
4   18          ?  103497  Some-college               10       Never-married

          occupation relationship   race  gender  capital-gain  capital-loss  \
0  Machine-op-inspct    Own-child  Black    Male             0             0
1    Farming-fishing      Husband  White    Male             0             0
2    Protective-serv      Husband  White    Male             0             0
3  Machine-op-inspct      Husband  Black    Male          7688             0
4                  ?    Own-child  White  Female             0             0

   hours-per-week native-country income marital-status2
0              40  United-States  <=50K           Never
1              50  United-States  <=50K           Marri 
2              40  United-States  >50K            Marri
3              40  United-States  >50K            Marri
4              30  United-States  <=50K           Never

 

末尾から切り出す文字列を指定した場合はマイナスをつけます。

例3

#  'marital-status'列の末尾から5文字をカットし、'marital-status2'を新規列として作成
data1['marital-status2'] = data1['marital-status'].str[-5:]

例3の結果

   age  workclass  fnlwgt     education  educational-num      marital-status  \
0   25    Private  226802          11th                7       Never-married
1   38    Private   89814       HS-grad                9  Married-civ-spouse
2   28  Local-gov  336951    Assoc-acdm               12  Married-civ-spouse
3   44    Private  160323  Some-college               10  Married-civ-spouse
4   18          ?  103497  Some-college               10       Never-married

          occupation relationship   race  gender  capital-gain  capital-loss  \
0  Machine-op-inspct    Own-child  Black    Male             0             0
1    Farming-fishing      Husband  White    Male             0             0
2    Protective-serv      Husband  White    Male             0             0
3  Machine-op-inspct      Husband  Black    Male          7688             0
4                  ?    Own-child  White  Female             0             0

   hours-per-week native-country income marital-status2
0              40  United-States  <=50K           rried
1              50  United-States  <=50K           pouse 
2              40  United-States  >50K            pouse
3              40  United-States  >50K            pouse
4              30  United-States  <=50K           rried

パターンに従って入っている文字列データの場合、不要な部分をカットしておきたい、というケースもあるかと思いますので、ご活用ください。