Click here to Skip to main content
16,017,151 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a string column which consists of various information from sentences to dates with punctuation's. When i remove punctuation, the dates are converting to text. Please let me know how to retain the dates.

Sample Input :

Column-1 

meet BM zaheer sir and converted 3 sme tiny 
Met BM Bhupesh kumar and Jayakrishnan sir
01-12-2017
MET BM BEENA - 9895580771
MET CHIEF - 9446486084
05-12-2017
05-12-2017
05-12-2017
Bm not available.
done
Branch meeting


Output :

Column-1 
meet BM zaheer sir and converted 3 sme tiny 
Met BM Bhupesh kumar and Jayakrishnan sir
43070
MET BM BEENA 9895580771
MET CHIEF 9446486084
43074
43074
43074
Bm not available
done
Branch meeting


What I have tried:

df['column-1'] = df['column-1'].str.replace('[^\w\s]','')
 df['column-1'].head()


 df = df.apply(lambda x: x.str.strip()).replace('', np.nan)

 null_columns=df.columns[df.isnull().any()]
 print(df[df["column-1"].isnull()][null_columns])

 import numpy as np
 df = df.replace(np.nan, 'null', regex=True)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900