Pandas: Create a time-series from a given list of dates as strings
6. Time-Series from Date Strings
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
For more Practice: Solve these Related Problems:
- Write a Pandas program to convert a list of date strings with inconsistent formats into a sorted DatetimeIndex.
- Write a Pandas program to create a time-series from an unsorted list of date strings and then resample it to a daily frequency.
- Write a Pandas program to transform a list of date strings into a time-series and forward-fill any missing dates.
- Write a Pandas program to convert date strings in a custom format into a time-series and then output the dates in ISO format.
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.