Hints for Exercise 7¶
Converting a column of date-strings into datetime format¶
In some cases Pandas cannot understand and parse automatically the date information from a column when you read the
data with read_csv()
function. In these cases, you need to parse the date information afterwards.
Let’s see an example with following data
DATE, Value
"201401", 1
"201402", 2
"201403", 3
"201404", 5
Let’s try to read the data and parse the date.
In [1]: data = pd.read_csv(fp, sep=',', parse_dates=['DATE'])
In [2]: data.head()
Out[2]:
DATE Value
0 201401 1
1 201402 2
2 201403 3
3 201404 5
In [3]: data.dtypes