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.



Follow us on Facebook and Twitter for latest update.