データフレームの任意の列について、列内の文字列を置換することを考えます。
日本語を英字に変換したい、など様々なケースが考えられます。

対象データ: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.replaceを使う

列を上書きしたいとき

例1

# data1のeducation列データの'-'を'_'に置換する
data1['education'] = data1['education'].str.replace('-', '_')

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

 

新規列として追加したいとき
例2

# data1のeducation列データの'-'を'_'に置換し、education2列として追加
data1['education2'] = data1['education'].str.replace('-', '_')

例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    education2
0              40  United-States  <=50K          11th
1              50  United-States  <=50K HS_grad 2 40 United-States >50K    Assoc_acdm
3              40  United-States   >50K  Some_college
4              30  United-States  <=50K  Some_college

 

当然、特殊文字が入っていたら、バックスラッシュでエスケープが必要(この場合、’?’を’\?’としてます。)
※正規表現は別途詳しく
例3

# data1のoccupation列データの'?'と'-'を'_'に置換する
data1["occupation"] = data1["occupation"].str.replace('\?|-', '_')

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

 

上記の例は、以下のようにも書けます。(python pandasでデータの列選択(文字列マッチ指定)参照)
例4

# data1のoccupation列データの'?'と'-'を'_'に置換する
searchfor = ["\?", "-"]
pattern = ("|".join(searchfor))

data1["occupation"] = data1["occupation"].str.replace(pattern, '_')
data1.head()

例4の結果

   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

例えば、「1,000円」といった金額が入っている文字列型のデータ列を「1000」という数値型に変換する場合などに重宝します。