Write a Pandas program to convert year-month string to dates adding a specified day of the month.
import pandas as pd from dateutil.parser import parse date_series = pd.Series(['Jan 2015', 'Feb 2016', 'Mar 2017', 'Apr 2018', 'May 2019']) print("Original Series:") print(date_series) print("\nNew dates:") result = date_series.map(lambda d: parse('11 ' + d)) print(result)
Sample Output:
Original Series: 0 Jan 2015 1 Feb 2016 2 Mar 2017 3 Apr 2018 4 May 2019 dtype: object New dates: 0 2015-01-11 1 2016-02-11 2 2017-03-11 3 2018-04-11 4 2019-05-11 dtype: datetime64[ns]
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer