In this python pandas program, we will convert a series of date strings to a time-series using pandas library.
Steps to solve the program
- Import pandas library as pd.
- Create a series of date strings using pd.Series().
- Convert a series of date strings to a time-series using pd.to_datetime(df).
- Print the output.
import pandas as pd
df = pd.Series(['2 Feb 2020','5/11/2021','7-8-2022'])
print("Original Series:")
print(df)
print("Converting series of date strings to a timeseries:")
print(pd.to_datetime(df))
Output :
Original Series:
0 2 Feb 2020
1 5/11/2021
2 7-8-2022
dtype: object
Converting series of date strings to a timeseries:
0 2020-02-02
1 2021-05-11
2 2022-07-08
dtype: datetime64[ns]
calculate the number of characters in each word in a series