import pandas as pd
Dates = [list(['None','11/04/1911', '03/06/1919']),
list(['None']),
list(['01/26/1912', '01/15/1918', '02/06/1917']),
list(['None'])]
df= pd.DataFrame({'Text':['Hey 10.31.11 22|1|13 03-02-1919 d',
'things here 01-23-18 or 03-23-1984 then ',
'stuff 1-22-12 01.11.18 or 2.2.17 so so ',
'nothing much'],
'ID': ['E1','E2', 'E3', 'E4'],
'Dates' : Dates,
})
which looks like
Dates ID Text
0 [None, 11/04/1911, 03/06/1919] E1 Hey 10.31.11 22|1|13 03-02-1919 d
1 [None] E2 things here 01-23-18 or 03-23-1984 then
2 [01/26/1912, 01/15/1918, 02/06/1917] E3 stuff 1-22-12 01.11.18 or 2.2.17 so so
3 [None] E4 nothing much
I have the following df
. My goal is to replace the ['None']
e.g. row 1
and 3
to an empty list []
. My desired output is
Dates ID Text New_Date
0 [None, 11/04/1911, 03/06/1919]
1 []
2 [01/26/1912, 01/15/1918, 02/06/1917]
3 []
I have looked Check for None in pandas dataframe and Python: most idiomatic way to convert None to empty string? and How to replace None only with empty string using pandas?
I have also tried
df['New_Date] = df['Dates].replace('None', list())
How do I achieve my desired output?