📜  对列进行 pandas 字符串操作 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:23.635000             🧑  作者: Mango

代码示例1
In [21]:

def func(string):
    a_new_string =string.replace('- ','_')
    a_new_string1 =a_new_string.replace('-','_')
    a_new_string2= a_new_string1.rstrip(' months')
    return a_new_string2

df['Time'] = df['Time'].apply(func)
df
Out[21]:
    Time
0    2_3
1    1_2
2  10_11
3    4_5