in dataframe particular column to string
df["fruit"] = df["fruit"].astype("|S")
in dataframe particular column to string
df["fruit"] = df["fruit"].astype("|S")
pandas string manipulation on column
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
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us