w3resource

Pandas: Create a time-series from a given list of dates as strings

Pandas Time Series: Exercise-6 with Solution

Write a Pandas program to create a time-series from a given list of dates as strings.

Sample Solution:

Python Code :

import pandas as pd
import numpy as np
import datetime
from datetime import datetime, date 
dates = ['2014-08-01','2014-08-02','2014-08-03','2014-08-04']
time_series = pd.Series(np.random.randn(4), dates)
print(time_series)

Sample Output:

2014-08-01    2.025858
2014-08-02    0.307073
2014-08-03   -0.903682
2014-08-04    0.056662
dtype: float64        

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Pandas program to create a time-series with two index labels and random values. Also print the type of the index.
Next: Write a Pandas program to create a time series object that has time indexed data. Also select the dates of same year and select the dates between certain dates.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/python-exercises/pandas/time-series/pandas-time-series-exercise-6.php