pandas string manipulation on column

Solutions on MaxInterview for pandas string manipulation on column by the best coders in the world

showing results for - "pandas string manipulation on column"
Milla
21 Apr 2019
1In [21]:
2
3def func(string):
4    a_new_string =string.replace('- ','_')
5    a_new_string1 =a_new_string.replace('-','_')
6    a_new_string2= a_new_string1.rstrip(' months')
7    return a_new_string2
8
9df['Time'] = df['Time'].apply(func)
10df
11Out[21]:
12    Time
130    2_3
141    1_2
152  10_11
163    4_5