In [1]:
import pandas as pd

In [2]:
s = pd.Series([' a-a-x ', ' b-x-b ', ' x-c-c '])
print(s)


0     a-a-x 
1     b-x-b 
2     x-c-c 
dtype: object

In [3]:
s_new = s.str.replace('x', 'z')
print(s_new)


0     a-a-z 
1     b-z-b 
2     z-c-c 
dtype: object

In [4]:
df = pd.DataFrame([[' a-a-x-1 ', ' a-a-x-2 '],
                   [' b-x-b-1 ', ' b-x-b-2 '],
                   [' x-c-c-1 ', ' x-c-c-2 ']],
                  columns=['col1', 'col2'])
print(df)


        col1       col2
0   a-a-x-1    a-a-x-2 
1   b-x-b-1    b-x-b-2 
2   x-c-c-1    x-c-c-2 

In [5]:
df['col1'] = df['col1'].str.replace('x', 'z')
print(df)


        col1       col2
0   a-a-z-1    a-a-x-2 
1   b-z-b-1    b-x-b-2 
2   z-c-c-1    x-c-c-2 

In [6]:
s_new = s.str.strip()
print(s_new)


0    a-a-x
1    b-x-b
2    x-c-c
dtype: object

In [7]:
s_new = s.str.strip(' x')
print(s_new)


0     a-a-
1    b-x-b
2     -c-c
dtype: object

In [8]:
df['col1'] = df['col1'].str.strip()
print(df)


      col1       col2
0  a-a-z-1   a-a-x-2 
1  b-z-b-1   b-x-b-2 
2  z-c-c-1   x-c-c-2 

In [9]:
s_new = s.str.lstrip()
print(s_new)


0    a-a-x 
1    b-x-b 
2    x-c-c 
dtype: object

In [10]:
s_new = s.str.rstrip()
print(s_new)


0     a-a-x
1     b-x-b
2     x-c-c
dtype: object

In [11]:
s = pd.Series(['Hello World', 'hello world', 'HELLO WORLD'])
print(s)


0    Hello World
1    hello world
2    HELLO WORLD
dtype: object

In [12]:
s_new = s.str.lower()
print(s_new)


0    hello world
1    hello world
2    hello world
dtype: object

In [13]:
s_new = s.str.upper()
print(s_new)


0    HELLO WORLD
1    HELLO WORLD
2    HELLO WORLD
dtype: object

In [14]:
s_new = s.str.capitalize()
print(s_new)


0    Hello world
1    Hello world
2    Hello world
dtype: object

In [15]:
s_new = s.str.title()
print(s_new)


0    Hello World
1    Hello World
2    Hello World
dtype: object